[Haskell] Simple IO Regions

Benjamin Franksen benjamin.franksen at bessy.de
Wed Jan 18 12:12:58 EST 2006


On Wednesday 18 January 2006 11:33, Simon Peyton-Jones wrote:
> I really like the way you use a set of constraints
> 	(IN m1 ms, IN m2 ms, IN m3 ms)
> to maintain the set of marks.  Previously I've thought of using a
> nested tuple type
> 	(m1, (m2, (m3 ())))
> to maintain the set, but that is far less convenient.  Very neat.

Nested tuples are more or less what the previous version (the one at 
http://okmij.org/ftp/Haskell/types.html#monadic-regions) was based on. 
(HLists are really almost the same as nested tuples).

> Why do you need the
> 	instance IN () b

As I understand it, one instance for some (arbitrary) type is needed so 
that an ordinary handle can be marked before passing it to a procedure 
passed as argument. For instance, in function 'withFile' the handle we 
get from openFile is marked by writing

  (Q handle) :: Q ()

Instead of '()' one could use an empty data type as well, like this:

  data Mark
  instance IN Mark b

  ...

  withFile path proc =
    ...
    (\handle -> unIOM $ proc ((Q handle) :: Q Mark)))

or a bit nicer:

  data Mark
  instance IN Mark b

  mark :: Handle -> Q Mark
  mark h = Q h

  ...

  withFile path proc =
    ...
    (\handle -> unIOM $ proc $ mark handle))

Ben


More information about the Haskell mailing list