|
|
> Erlang has first-class functions as well as closures. Indeed, there are
> warnings in the docs saying things like "take care if you store a
> closure in a database that when you fetch it back out to run it, you're
> running the same version of the interpreter." :-)
Ooo. So much for "you can upgrade stuff in-place without shutting down". :-P
[Mind you, persistent *closures*? That's got to be a fairly rarely used
feature...]
> I think I'll have to find a good explanation of monads again. :-)
The I/O monad is unusual as monads go, but essentially the I/O functions
return I/O command objects instead of actually *performing* I/O, and you
use the monad operators to join all those actions together until the
"main" function essentially returns a *gaint* I/O command object that
represents the operation of the entire program. [Obviously, containing
lots of closures!]
This is only the conceptual model; in practice the compiler actually
generates much the same code as a C compiler would. But it *does* mean
that an "I/O action" is first-class, just like a function is...
There are famously "two ways" to look at monads. You can look as a monad
as a kind of "container", or you can look at a monad as representing an
"action" that can have special effects. In the former case, it's
probably best to start by learning about the I/O monad. In the latter
case, the Maybe and list monads are probably an easier starting point...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|