[Haskell-cafe] Syntax of 'do'

Philip Weaver philip.weaver at gmail.com
Fri Aug 29 11:37:03 EDT 2008


On Fri, Aug 29, 2008 at 6:41 AM, Maurí­cio <briqueabraque at yahoo.com> wrote:

> Hi,
>
> http://haskell.org/haskellwiki/Keywords says that:
>
> -------------
> [do is a] syntactic sugar for use with monadic
> expressions. For example:
>
>  do { x ; result <- y ; foo result }
>
> is shorthand for:
>
>  x >> y >>= \result -> foo result
> -------------
>
> I did some tests hiding Prelude.>> and Prelude.>>=
> and applying >> and >>= to non-monadic types, and
> saw that 'do' would not apply to them. So, I would
> like to add the following to that text:
>

It sounds like you tried to redefine (>>) and (>>=) and make 'do' use the
new definitions.  This is not possible, regardless of what types you give
(>>) and (>>=).

If you want to define (>>) and (>>=), do so for a particular instance of
Monad.


> -------------
> as long as proper types apply:
>
> x :: Prelude.Monad a
> y :: Prelude.Monad b
> foo :: b -> Prelude.Monad c
> -------------
>
> Is that correct (Haskell and English)?
>
> Thanks,
> Maurício
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080829/5694026c/attachment.htm


More information about the Haskell-Cafe mailing list