[Haskell-beginners] <-

David McBride toad3k at gmail.com
Fri Aug 31 05:09:08 CEST 2012

It is a syntatic sugar that is expanded to

getLine >>= \x -> putStrLn $ reverse x

>>= is defined in the typeclass for Monad.

In general, if something is using <- notation, it's type is Monad m => m a,
where m could be any of many monads, IO, Maybe, [] (lists), Parser or even
some type of yours that you made an instance of Monad, which you can do if
you would like to use that syntax.

On Thu, Aug 30, 2012 at 11:00 PM, Patrick Redmond <plredmond at gmail.com>wrote:

> I'm reading "Learn You a Haskell for Great Good!", chapter 9, "Input
> and Output" <http://learnyouahaskell.com/input-and-output>.
> IO actions are given liberal coverage throughout the chapter, however
> it is never mentioned whether the value-extractor syntax (<-) has a
> type or not.
> main = do
>     x <- getLine
>     putStrLn $ reverse x
> In this little program, getLine has type "IO String" and x has type
> "String". This implies to me that (<-) has type "IO a -> a". However,
> GHCI chokes on ":t (<-)" and Hoogle says it's just a syntactic element
> <http://www.haskell.org/haskellwiki/Keywords#.3C->.
> I guess I don't have a specific question, but I was kind of expecting
> it to be a function with a type because everything seems to be a
> function with a type in Haskell... Thanks for listening!
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120830/dee5859f/attachment.htm>

More information about the Beginners mailing list