do's and error messages

Simon Peyton-Jones
Mon, 16 Jul 2001 09:48:46 -0700

Here's an example:

	f x =3D do { "c" ; putStrLn "x"; return () }

    Couldn't match `[]' against `IO'
	Expected type: [t]
	Inferred type: IO ()
    In the application `putStrLn "x"'
    in a `do' expression pattern binding: putStrLn "x"

I don't see an easy way to improve this.  I suppose we could
do some kind of "voting" thing, where we take a majority view about=20
what the result type constructor of the monad is... but that would
take a bit of work.

Hmm.    It's a good point, but I'm inclined to wait until there are more
yells before investing effort here. =20


| -----Original Message-----
| From: George Russell []=20
| Sent: 16 July 2001 15:56
| To:
| Subject: do's and error messages
| If you have a type error message at the very start of a "do"=20
| statement, the result can be rather confusing, because the=20
| typechecker doesn't "know" that do's are almost always have=20
| type (IO (something)) and so tries to shoehorn the monad to=20
| fit the type.  This has actually happened to me several=20
| times; the worst case is when the result is (for example) a=20
| list, which allows the error to propagate further.  Is there=20
| some way of doing something about this?
| _______________________________________________
| Glasgow-haskell-users mailing list=20
|| haskell-users