[Haskell-cafe] Should "do 1" compile

Joshua Ball sciolizer at gmail.com
Wed May 23 19:19:46 EDT 2007


While we're on the topic of coupling/cohesion of types and syntactic
sugar (and because sometimes problems are made easier by generalizing
them), I have a question.

What is the rationale for disallowing the following code?

main = print "Type 'True' on three lines or I will quit." >> foo

foo = [ () | line1 <- readLn, line1, line2 <- readLn, line2, line3 <-
readLn, line3]

Obviously this example is contrived, and you'd never want to use the
list comprehension syntax for the IO monad. But you might want to for,
say, the probability monad. Isn't that enough reason enough to
decouple the sugar from the typing? (Though I agree with Claus that
cryptic error messages are a bad thing.)

On 5/23/07, Stefan Holdermans <stefan at cs.uu.nl> wrote:
> Spencer,
>
> > How about:
> >
> >  do x ==> (x :: Monad m => m a)
>
> That one does not do it, because now you demand x to be polymorphic
> in all monad types m and all monad-element types a, which I guess
> restricts x to
>
>    undefined
>
> and
>
>    return undefined
>
> and combinations thereof, glued together by monadic binds.
>
> >   do x ==> (asTypeOf x (return ()))
>
> Again, no, for now you restrict the element type to () and, hence,
> you preclude, for instance,
>
>    do return False
>
> Cheers,
>
>    Stefan
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list