Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell mutability in compiled state?

I do not know much about Haskell, but from what I have read about the mutability of computations (e.g: functions returning functions, complex monads and functions, etc.) it seems like you can do a lot of meta-programming, even at runtime.

  • How can Haskell, if everything like functions and monads are so complex, compile to machine code and retain all this?
like image 437
pile of junk Avatar asked Dec 30 '25 07:12

pile of junk


2 Answers

I'm not sure what you mean by "mutability" precisely, but it is certainly the case that compiling such an abstract language to efficient machine code is a complicated task. As a starting point, you could read The Implementation of Functional Programming Languages, a book by Simon Peyton-Jones, one of the main people behind Haskell.

For something more recent, there's some commentary on the internals of GHC, the flagship Haskell compiler.

On a more down-to-earth note, if it's just the idea of "functions as values" that you're wondering about, that's old hat--Lisp dialects have been compiling higher-order functions for longer than I've been alive, and even C passes pointers to functions around.

like image 112
C. A. McCann Avatar answered Jan 02 '26 01:01

C. A. McCann


How can Haskell ... compile to machine code ...?

Via this compilation strategy: Implementing Lazy Functional Languages on Stock Hardware

like image 38
Don Stewart Avatar answered Jan 02 '26 00:01

Don Stewart