thunk

Can we implement c++ thunk in linux?

天大地大妈咪最大 提交于 2021-02-10 09:29:12
问题 I want to use class member functions as callbacks, I don't use libsigc, because it's slow. In ATL, we can use member function for C-style callback(http://www.codeproject.com/KB/cpp/SoloGenericCallBack.aspx), so can we implement c++ thunk in linux? The code below will crash: #include <assert.h> #include <stdio.h> #include <sys/mman.h> typedef char BYTE; typedef int DWORD; typedef int* DWORD_PTR; typedef int* INT_PTR; typedef bool BOOL; typedef unsigned long ULONG; typedef unsigned long* ULONG

Are thunk and function currying the same?

牧云@^-^@ 提交于 2020-05-23 11:59:45
问题 When I learn thunk, I think they are like function currying. Why is it called thunk? Thunk function add(x, y){ return x + y } function thunk() { return add(10, 20) } Function currying function multiply(a, b, c) { return a * b * c; } function multiply(a) { return (b) => { return (c) => { return a * b * c } } } 回答1: No they are quite different. However, both thunks and currying have applications in functional programming . Thunks Thunks are a functional programming technique used to delay

Haskell Fibonacci Explanation

寵の児 提交于 2019-12-29 07:33:26
问题 I am quite new to Haskell and I'm trying to wrap my head around how the lazy expression of Fibonacci sequences work. I know this has been asked before, but none of the answers have addressed an issue I'm having with visualising the result. The code is the canonical one using zipWith fibs = 0 : 1 : zipWith (+) fibs (tail fibs) I understand the following: zipWith literally zips two lists together tail grabs all but the first element of a list Haskell references 'to-be' computed data as thunks .

How do non-static callbacks work from native code?

♀尐吖头ヾ 提交于 2019-12-22 07:36:12
问题 It's a bit odd asking this question, because I have code that seems like it shouldn't work, but it does, and although I'm not complaining, I'd like to confirm why? LOL Simply, I have a C++ native DLL (no CLR/managed support at all) that takes a call-back from C# code. The native side stores an stdcall callback function, which is supplied by the C# side. I always thought the callback METHOD (in C#) had to be static, but non-static and lambda expression BOTH work JUST FINE!? How is the "this"

why foldl is not short circuiting with andFn function?

99封情书 提交于 2019-12-22 05:32:14
问题 My understanding is that foldl and foldr executes like : foldl f a [1..30] => (f (f (f ... (f a 1) 2) 3) ... 30) and foldr f a [1..30] => (f 1 (f 2 (f 3 (f ....(f 30 a)))))..) so.. foldr (&&) False (repeat False) can shortciruit as outermost f sees (&&) False ((&&) False (....)) sees first argument as false and does not need to evaluate the second argument (which is a large thunk). so what happens with andFn :: Bool -> Bool -> Bool andFn _ False = False andFn x True = x and foldl andFn True

How to thunk a function in x86 and x64? (Like std::bind in C++, but dynamic)

左心房为你撑大大i 提交于 2019-12-19 03:40:49
问题 How do I thunk an arbitrary function with an arbitrary (fixed) number of arguments, on x86 and x64? (I don't need floating-point, SSE, or the like. The arguments are all integers or pointers.) 回答1: Here's my generic implementation. I initially made it with AsmJit, then modified it by hand to remove the dependency. It works for both x86 and x64! It works for both cdecl and stdcall! It should also work for "thiscall", both on VC++ and GCC, but I haven't tested it. (VC++ would probably not touch

How to pass a method as callback to a Windows API call (Follow-up)?

风格不统一 提交于 2019-12-19 03:26:10
问题 This post is a follow-up of a related question posted here by Ran. The accepted answer sticks to the use of the usual a plain old function. This excerpt particularly catch my attention: An instance method has an extra, implicit, parameter containing the instance reference, i.e. Self. With the firm conviction that there should be a way to use a kind of "parameters" adapter (to rephrase get rid of the uneeded Self implicit reference and provide a pointer to a complying adapted callback function

What is a 'thunk'?

别来无恙 提交于 2019-12-17 05:36:08
问题 I've seen it used in programming (specifically in the C++ domain) and have no idea what it is. Presumably it is a design pattern, but I could be wrong. Can anyone give a good example of a thunk? 回答1: A thunk usually refers to a small piece of code that is called as a function, does some small thing, and then JUMP s to another location (usually a function) instead of returning to its caller. Assuming the JUMP target is a normal function, when it returns, it will return to the thunk's caller.

What is a 'thunk'?

回眸只為那壹抹淺笑 提交于 2019-12-17 05:35:01
问题 I've seen it used in programming (specifically in the C++ domain) and have no idea what it is. Presumably it is a design pattern, but I could be wrong. Can anyone give a good example of a thunk? 回答1: A thunk usually refers to a small piece of code that is called as a function, does some small thing, and then JUMP s to another location (usually a function) instead of returning to its caller. Assuming the JUMP target is a normal function, when it returns, it will return to the thunk's caller.

Test if a value has been evaluated to weak head normal form

送分小仙女□ 提交于 2019-12-12 07:32:43
问题 In Haskell, is it possible to test if a value has been evaluated to weak head normal form? If a function already exists, I would expect it to have a signature like evaluated :: a -> IO Bool There are a few places that similar functionality lives. A previous answer introduced me to the :sprint ghci command, which will print only the portion of a value that has already been forced to weak head normal form. :sprint can observe whether or not a value has been evaluated: > let l = ['a'..] >