<div dir="ltr"><div>Without a type signature, all GHCI knows:</div><div><br></div><div>    Prelude> :t read "2"</div><div>    read "2" :: Read a => a</div><div><br></div><div>is that it should return some kind of Read -- that is, something that can be from a string. GHCI is not being asked to return any (concrete) type.</div><div><br></div><div>If you specify a type -- and if that type can be expressed as a string containing a single digit -- then it works:</div><div><br></div><div>    Prelude> read "2" :: Float</div><div>    2.0</div><div><br></div><div>And otherwise it won't:</div><div><br></div><div>    Prelude> read "2" :: [Float]</div><div>    *** Exception: Prelude.read: no parse</div><div><br></div><div>You don't necessarily have to provide a type signature, though, if it can be inferred from context:</div><div><br></div><div>    Prelude> floor $ read "2"</div><div>    2</div><div>    Prelude> :t floor</div><div>    floor :: (Integral b, RealFrac a) => a -> b</div><div>    Prelude> :t floor $ read "2"</div><div>    floor $ read "2" :: Integral b => b</div><div><br></div><div>Note that GHCI in this case still does not know exactly the type of (floor $ read "2"), but thanks to the type of floor, it knows enough to proceed.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 27, 2016 at 11:38 AM, David Kraeutmann <span dir="ltr"><<a href="mailto:kane@kane.cx" target="_blank">kane@kane.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">GHCi enables -XExtendedDefaultRules, which cause read "2" to default to ().<br>
<div><div class="h5">On 5/27/2016 8:28 PM, Erik Rantapaa wrote:<br>
> Hi fellow Haskellers!<br>
><br>
> If I bring up ghci and evaluate `read 2` I get the error "Prelude.read: no<br>
> parse"<br>
><br>
> GHCi, version 7.10.2: <a href="http://www.haskell.org/ghc/" rel="noreferrer" target="_blank">http://www.haskell.org/ghc/</a>  :? for help<br>
> Prelude> read "2"<br>
> *** Exception: Prelude.read: no parse<br>
><br>
> Exactly how is this message coming about? I understand that `read` needs a<br>
> return type in order to determine which type class instance to run. So, in<br>
> this case, which type is `read` being asked to return?<br>
><br>
> Thanks,<br>
> Erik<br>
><br>
><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
><br>
<br>
<br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Jeffrey Benjamin Brown</div></div>
</div>