[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-beginners
Subject: Re: [Haskell-beginners] <-
From: Karl Voelker <ktvoelker () gmail ! com>
Date: 2012-08-31 3:54:43
Message-ID: CAFfow0z2a71hn6z1bO5=V2V0EH_wnb5z3nApiiVEaRfP-NFX-A () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
On Thu, Aug 30, 2012 at 8:00 PM, Patrick Redmond <plredmond@gmail.com>wrote:
> IO actions are given liberal coverage throughout the chapter, however
> it is never mentioned whether the value-extractor syntax (<-) has a
> type or not.
>
What sorts of things have types? Values have types, but x <- getLine is not
a value. I will elaborate.
> main = do
> x <- getLine
> putStrLn $ reverse x
>
>
As mentioned by others, this can be de-sugared into:
main = getLine >>= \x -> 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->.
>
You are right about the types of getLine and x. But look at the part of the
de-sugared code that corresponds to x <- getLine:
getLine >>= \x ->
This isn't an expression. In fact, it's nothing valid on its own. Since you
can't evaluate it to a value, don't expect it to have a type.
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!
>
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.)
-Karl V.
[Attachment #5 (text/html)]
On Thu, Aug 30, 2012 at 8:00 PM, Patrick Redmond <span dir="ltr"><<a \
href="mailto:plredmond@gmail.com" target="_blank">plredmond@gmail.com</a>></span> \
wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 \
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> IO actions are given liberal \
coverage throughout the chapter, however<br> it is never mentioned whether the \
value-extractor syntax (<-) has a<br> type or \
not.<br></blockquote><div><br></div><div>What sorts of things have types? Values have \
types, but x <- getLine is not a value. I will elaborate.</div><div> \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">
main = do<br>
x <- getLine<br>
putStrLn $ reverse x<br>
<br></blockquote><div><br></div><div>As mentioned by others, this can be de-sugared \
into:</div><div><br></div><div>main = getLine >>= \x -> putStrLn $ reverse \
x</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">
In this little program, getLine has type "IO String" and x has type<br>
"String". This implies to me that (<-) has type "IO a -> \
a". However,<br> GHCI chokes on ":t (<-)" and Hoogle says it's \
just a syntactic element<br> <<a \
href="http://www.haskell.org/haskellwiki/Keywords#.3C-" \
target="_blank">http://www.haskell.org/haskellwiki/Keywords#.3C-</a>>.<br></blockquote><div><br></div><div>You \
are right about the types of getLine and x. But look at the part of the de-sugared \
code that corresponds to x <- getLine:</div> <div><br></div><div>getLine >>= \
\x -></div><div><br></div><div>This isn't an expression. In fact, it's \
nothing valid on its own. Since you can't evaluate it to a value, don't \
expect it to have a type.</div> <div><br></div><blockquote class="gmail_quote" \
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> I guess I \
don't have a specific question, but I was kind of expecting<br> it to be a \
function with a type because everything seems to be a<br> function with a type in \
Haskell... Thanks for listening!<br></blockquote><div><br></div><div>There are other \
things in Haskell which don't have a type. Here's something very similar to \
your example:</div><div><br> </div><div>foo = let x = 3 in x + \
x</div><div><br></div><div>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.)</div><div><br></div> <div>-Karl V. </div></div>
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic