2
$\begingroup$

Defunctionalization is nice for higher order functions where it is completely necessary to avoid runtime support, but in some cases it's favourable to use function pointers instead (since they don't generate huge code bloat for certain scenarios, i.e.):

data Foo a = Foo (a -> Int)

Under what conditions is it safe to implement higher order calls using function pointers instead of reducing them to huge switch tables of static calls?

My initial thought is that it has something to do with known arity.

$\endgroup$
  • 1
    $\begingroup$ I'm confused. When is arity unknown? $\endgroup$ – Karolis Juodelė May 18 '14 at 11:16
  • $\begingroup$ For example, in Haskells notation; map :: (a -> b) -> [a] -> [b], the arity of the first argument is not actually known since it could be partially applied. i.e., it could be used outside the current module like map (transform 1 2 3 4) [1..5] or just map (+1) [1..5]. In both cases the type is a -> b but the arity is different. $\endgroup$ – kvanberendonck May 18 '14 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.