do's and error messages

2001-07-16 Thread George Russell

If you have a type error message at the very start of a do statement, the result
can be rather confusing, because the typechecker doesn't know that do's are
almost always have type (IO (something)) and so tries to shoehorn the monad
to fit the type.  This has actually happened to me several times; the worst
case is when the result is (for example) a list, which allows the error to
propagate further.  Is there some way of doing something about this?

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



RE: do's and error messages

2001-07-16 Thread Simon Peyton-Jones

Here's an example:

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

Test.hs:3:
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 
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.  

Simon

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

___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



Re: do's and error messages

2001-07-16 Thread Ken Shan

On 2001-07-16T09:48:46-0700, Simon Peyton-Jones wrote:
 Here's an example:
   f x = do { c ; putStrLn x; return () }

Would

asIO :: IO a - IO a
asIO = id

help here?

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
See the sun in the midst of the rain. 
Scoop clear water from the heart of the fire.

 PGP signature