From paqui.lucio at ehu.es Fri Jan 11 10:49:26 2008 From: paqui.lucio at ehu.es (Paqui Lucio) Date: Fri Jan 11 10:43:03 2008 Subject: [Hugs-users] wrong infered types? Message-ID: <005501c85469$8b358960$a471e39e@SIPC64> 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 --------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/hugs-users/attachments/20080111/9131315c/attachment.htm From ndmitchell at gmail.com Fri Jan 11 10:57:21 2008 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Jan 11 10:50:50 2008 Subject: [Hugs-users] wrong infered types? In-Reply-To: <005501c85469$8b358960$a471e39e@SIPC64> References: <005501c85469$8b358960$a471e39e@SIPC64> Message-ID: <404396ef0801110757i1b01e989n41ae9ad2b447ca66@mail.gmail.com> 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