[Haskell-cafe] Should "do 1" compile

Spencer Janssen sjanssen at cse.unl.edu
Wed May 23 15:17:01 EDT 2007


On Wed, 23 May 2007 19:54:27 +0100
"Neil Mitchell" <ndmitchell at gmail.com> wrote:
> Hi
> 
> > > foo = do (1 :: Int)
> >
> > While intuitively this should be disallowed, it seems a pity that
> > desugaring couldn't be totally separated from typechecking. Hmm.
> 
> You can always desugar as:
> 
> do x ==> return () >> x
> 
> Although then you are relying on the Monad laws more than you possibly
> should. You could also have:
> 
> monady :: Monad m => m a -> m a
> monady x = x
> 
> do x ==> monady x

How about:

 do x ==> (x :: Monad m => m a)

Or even:

 do x ==> (asTypeOf x (return ()))


Cheers,
Spencer Janssen


More information about the Haskell-Cafe mailing list