6

GHC's Core data type represents recursion with recursive binders in the Let constructor; as I understand it, all let expressions in Haskell are effectively let rec expressions. Why does GHC use this method of representing recursion instead of an atomic fixpoint operator?

  • Why shouldn't it? – cHao Apr 30 '18 at 15:03
  • Not sure why GHC specifically does this, but I’ll take a wild guess that it’s just about making it convenient to implement efficiently. If you have let ones = 1 : ones you can compile it directly to something like ones = { push ones; push 1; jump (:) }, while with the desugared version, let ones = fix (\ self -> 1 : self), you have to recognise that you can inline the lambda and avoid the allocation of a thunk for the application of the lambda to its own application. Presumably it’s also more convenient to work with a group of recursive let bindings than the same in terms of fix. – Jon Purdy May 8 '18 at 18:15

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.