
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: ------------- 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

-XNoImplicitPrelude ? On 29 Aug 2008, at 17:41, Maurí cio 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:
------------- 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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hello Mauricio, Friday, August 29, 2008, 5:41:41 PM, you wrote: afaik, this shorthand isn't exact. actually there is more code dealing with fails and this code use Monad operations
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:
------------- 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, Mauricio
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

2008/8/29 Maurício
x :: Prelude.Monad a y :: Prelude.Monad b foo :: b -> Prelude.Monad c
Monad is not a type, it is a type class, so you probably mean: x :: Monad m => m a y :: Monad m => m b foo :: Monad m => b -> m c With the further understanding that all three `m's must be the same. -- -David

On Fri, Aug 29, 2008 at 6:41 AM, Maurício
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2008/8/29 Philip Weaver
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 (>>=).
Watch out for rebindable syntax: http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#re... At first reading, I thought that -XNoImplicitPrelude was required to turn this on. But now I'm not sure: it seems that if you hide Prelude.>>= and Prelude.return, that ought to be enough to make do notation work with your alternative definitions. I'm not at home, so I can't try this right now. -- -David

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 (>>=).
Watch out for rebindable syntax: (...)
At first reading, I thought that -XNoImplicitPrelude was required to turn this on. But now I'm not sure: (...)
I wrote this test to check your sugestion. It does build with -XNoImplicitPrelude, but not without it: ---------- module Test where { import Prelude hiding ( ( >> ) , ( >>= ) ) ; data PseudoMonad a = PseudoMonad a ; ( >> ) = \(PseudoMonad x) (PseudoMonad _) -> PseudoMonad x ; ( >>= ) = (\(PseudoMonad a) f -> f a) :: PseudoMonad Integer -> (Integer -> PseudoMonad Integer) -> PseudoMonad Integer; plusOne n = (PseudoMonad (n + 1)) :: PseudoMonad Integer; c = (PseudoMonad 1) >> ((PseudoMonad 2) >>= (\n -> plusOne n)); d = do {(PseudoMonad 1) ; a <- (PseudoMonad 2) ; plusOne a } } ---------- It's interesting that the types involved in >>= etc. should still be like "t t1", that's why I had to create PseudoMonad. Using just Integer (i.e., 2
3 would be valid) doesn't work, even if all operators are defined accordingly.
Best, Maurício

On Fri, Aug 29, 2008 at 8:50 AM, David House
2008/8/29 Philip Weaver
: 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 (>>=).
Watch out for rebindable syntax:
http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#re...
Oh, I had no idea! Thanks :).
At first reading, I thought that -XNoImplicitPrelude was required to turn this on. But now I'm not sure: it seems that if you hide Prelude.>>= and Prelude.return, that ought to be enough to make do notation work with your alternative definitions. I'm not at home, so I can't try this right now.
-- -David
participants (5)
-
Bulat Ziganshin
-
David House
-
Maurício
-
Miguel Mitrofanov
-
Philip Weaver