[Haskell-beginners] <-

Patrick Redmond plredmond at gmail.com
Sat Sep 1 16:42:15 CEST 2012

On Thu, Aug 30, 2012 at 11:09 PM, David McBride <toad3k at gmail.com> wrote:
> It is a syntatic sugar that is expanded to
> getLine >>= \x -> putStrLn $ reverse x
>>>= is defined in the typeclass for Monad.

Interesting. Does that mean the lines following a "x <- getLine" are
simply balled up into a function? What if there are multiple lines?

main = do
    fn <- getLine
    ln <- getLine
    putStr $ reverse ln
    putStr " "
    putStr $ reverse fn

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

I thought it might start to get at monads..

On Thu, Aug 30, 2012 at 11:10 PM, Tony Morris <tonymorris at gmail.com> wrote:
> The (<-) symbol is syntax, so doesn't really have a type and probably
> shouldn't be thought of as having one.
> It's more like, given the expression that appears to its right of the
> type (m a) implies that the value to its left is of the type a.

And then that implication is realized through the syntactic
transformation which occurs when (<-) is desugared..? I'll keep

On Thu, Aug 30, 2012 at 11:54 PM, Karl Voelker <ktvoelker at gmail.com> wrote:
> There are other things in Haskell which don't have a type. Here's something
> very similar to your example:
> foo = let x = 3 in x + x
> Does "let x = 3" have a type? Does the "=" in there have a type? (The answer
> is no, and the reasons are basically the same.)

I've taken a pl class in which we learned that "let <name> = <expr1>
in <expr2>" is implemented by expanding to something like "(\<name> ->
<expr2>) <expr1>", so I'm familiar with this, but I appreciate your
making the parallel to (<-). Thanks!

More information about the Beginners mailing list