[Hat] Pattern match errors in do?

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Thu Jul 6 05:35:44 EDT 2006


"Neil Mitchell" <ndmitchell at gmail.com> wrote:

> > A pattern match failure in a "do" will call "fail" (not "error" as
> > other pattern match failures do). This is the "fail" of the IO
> > monad, which calls "ioError".
> 
> I believe according to Haskell 98, fail in the IO monad calls error -
> its only recent extension to GHC/Hugs which have resulted in ioError
> and exceptions. Perhaps for the purposes of hat stuff, error should be
> called instead? At least until a proper exception story can be
> developed.

The problem is, that would require type information about which monad
the 'do' block belongs to.  For IO, it might be fine for a pattern-match
failure to call 'error', but it would be totally incorrect for, say, the
Maybe monad, or the list monad, where fail might be defined as e.g.
'const Nothing' or 'const []'.

Regards,
    Malcolm


More information about the Hat mailing list