[Haskell-cafe] Haskell Cloud and Closures

Chris Smith cdsmith at gmail.com
Sat Oct 1 17:35:23 CEST 2011

On Sat, 2011-10-01 at 02:16 -0700, Fred Smith wrote:
> In seems to me that in cloud haskell library the function's closures
> can be computed only with top-level ones, is it possible to compute
> the closure at runtime of any function and to send it to another host?

The current rule is a bit overly restrictive, true.  But I just wanted
to point out that there is a good reason for having *some* restriction
in place.  There are certain types that should *not* be sent to other
processes or nodes.  Take MVar, for example.  It's not clear what it
would mean to send an MVar over a channel to a different node.

By extension, allowing you to send arbitrary functions not defined at
the top level is also problematic, because such functions might close
over references to MVars, making them essentially a vehicle for
smuggling MVars to new nodes.  And since the types of free variables
don't occur in the types of terms, there is no straight-forward Haskell
type signature that can express this limitation.  So the compiler is
obliged to specify some kind of sufficient restrictions to prevent you
from sending functions that close over MVar or other node-specific

For now, you'll have to move all of your functions to the top level.
Hopefully, in the future, some relaxation of those rules can occur.


More information about the Haskell-Cafe mailing list