[Haskell] Views in Haskell

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Jan 24 10:57:21 EST 2007


Duncan Coutts <duncan.coutts at worc.ox.ac.uk> wrote:

> > Using the '<-' arrow does not seem to obscure
> > this feature too much:
> >       parsePacket ((n, (val,bs) <- bits n) <- bits 3) = ...
> > vs
> >       parsePacket (bits 3 -> (n, (bits n -> val bs))) = ...
> 
> The main drawback to this is that we don't get the left to right
> binders and uses.

Actually, in _both_ forms, the 'n' is bound as a variable to the left of
("before") its usage in a view expression.  (But I agree that the '<-'
form does not flow as nicely when reading from left to right.)

> I guess that means the RHS has to be in the monad. What's different
> from an ordinary do is that failure in the monad somehow becomes
> pattern match failure.

I think the proposed extension 2 is really nice, primarily because no
monads are required at all.  Pattern match failure remains almost
exactly as it is in Haskell'98, with no extra Maybe type or MonadPlus
context or anything.  It is really simple and straightforward.

Regards,
    Malcolm


More information about the Haskell mailing list