Search Haskell Channel Logs

Monday, February 20, 2017

#haskell channel featuring monochrom, ezyang, suzu, Axman6, soulisson, Welkin,

soulisson 2017-02-20 16:28:55
Hi, how haskell passes functions to other functions? Does it pass a reference to the function?
soulisson 2017-02-20 16:29:09
(in memory address)?
ezyang 2017-02-20 16:29:34
soulisson: Like most languages, it passes a "closure", containing both the function code to run, and its lexically captured variables
Axman6 2017-02-20 16:32:14
ezyang: the function may be inlined at compile time too though right?
soulisson 2017-02-20 16:32:28
ezyang: so each time, the function code is duplicated and passed to the target function?
Axman6 2017-02-20 16:32:28
I believe the answer isn't quite as simple as a closure is passed
ezyang 2017-02-20 16:32:28
the function code doesn't change, so in C-parlance, you can just pass the function pointer
Axman6 2017-02-20 16:32:28
soulisson: there's no need for the function code to be duplicated as it can never change
ezyang 2017-02-20 16:32:28
If you have ever seen the convention in C where you pass both a function pointer and a void* pointer, that data together is a "closure"
soulisson 2017-02-20 16:32:28
Axman6, ezyang, ok, thank you
soulisson 2017-02-20 16:34:05
I've seen function pointers in C, for the convention you're talking about, I don't know it
Welkin 2017-02-20 16:34:58
ezyang: isn't the void* the data?
ezyang 2017-02-20 16:36:41
well, it's the data you want the function to have access to
ezyang 2017-02-20 16:36:52
that is, the function that the funptr points to
ezyang 2017-02-20 16:39:48
(and yes, C programmers don't use closures very often)
suzu 2017-02-20 16:40:42
i would if they werent so unsafe and tricky
monochrom 2017-02-20 16:42:27
C lacks inner functions. This and related concepts such as closures are bound to be alien to most C programmers.
suzu 2017-02-20 16:43:21
C is hard enough to get right as-is
soulisson 2017-02-20 16:44:23
I have a terminology question. Is it incorrect to say a C function that accept a function ptr is a higher order function?
monochrom 2017-02-20 16:44:40
I think it's correct.
soulisson 2017-02-20 16:45:05
ok, thanks