[Haskell] threading mutable state through callbacks

Jules Bean jules at jellybean.co.uk
Wed Oct 13 07:43:31 EDT 2004


On 12 Oct 2004, at 22:49, MR K P SCHUPKE wrote:

>> All we really need is a 'unique value monad' to give us unique values
>
> This sounds a lot like Clean's unique-types?
>

No, that's a confusion of terminology.

'Unique types' are type which have only one member. 'RealWorld' in 
haskell is rather like one of these (IO a == ST RealWorld a). They are 
a way of enforcing threading (sequential computation) which is 
"lighter-weight" in some sense than monads.

'A unique value monad' is just a monad whose job it is to dole out 
fresh values:

do
  a <- fresh
  b <- fresh
  insertDBRecord(a,"Bean")
  insertDBRecord(b,"Schupke")

..such as you might for record identifiers, or whatever. It's trivial 
to implement one in haskell. What I meant by saying that its almost 
commutative is that, for any implementation, if you reverse 'a <- 
fresh' and 'b <- fresh' you probably do get different answers, but it 
doesn't matter, because the specification is merely that they be 
different from each other. The algorithm which generates the numbers is 
opaque to the consumer anyway.

The IO monad is a whole lot more than a unique value monad, but the 
'newIORef' command is a much like 'fresh' above. My point was just that 
for global variables, we don't necessarily need a top-level IO monad 
(which gives you ordering concerns) just a top-level fresh value monad 
(which is essentially commutative, so you don't have ordering 
concerns).

Jules



More information about the Haskell mailing list