Hi, In Hugs, the infered types for the following four functions: f a = let m = id a in do return m f' a = do m <- id a return m g a = let m =[a,a] in do return m g' a = do m <- [a,a] return m respectively are f :: Monad a => b -> a b f' :: Monad a => a b -> a b g :: Monad a => b -> a [b] g' :: a -> [a] I didn't expect this types, do you? Anybody has some explanation? Thanks in advance, Paqui --------------------------------- Paqui Lucio Dpto de LSI Facultad de Informática Paseo Manuel de Lardizabal, 1 20080-San Sebastián SPAIN --------------------------------- e-mail: paqui.lucio@ehu.es Tfn: (+34) (9)43 015049 Fax: (+34) (9)43 015590 Web: http://www.sc.ehu.es/paqui ---------------------------------
Hi In future, you are probably best off addressing these general questions to the haskell-cafe@ mailing list.
f a = let m = id a in do return m
We can simplify this to: f a = let m = id a in do return m f a = let m = a in do return m f a = do return a f a = return a This shows why f has the same type as return.
f' a = do m <- id a return m
f' a = id a >>= \m -> return m f' a = a >>= \m -> return m You basically return a, but have sent it through >>= which means it must be monadic.
g a = let m =[a,a] in do return m
g a = return [a,a]
g' a = do m <- [a,a] return m
This is the tricky one. Here your use of m <- [a,a] has bound the Monad in question to be the list Monad, hence you get a result in terms of lists, not monads. do notation applies to any monad, including list. Thanks Neil
participants (2)
-
Neil Mitchell -
Paqui Lucio