<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 1, 2015 at 12:58 PM, Nikita Karetnikov <span dir="ltr"><<a href="mailto:nikita@karetnikov.org" target="_blank">nikita@karetnikov.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> You can indeed write "Maybe a -> a" function easy, because you have Maybe<br>
> constructors exported for you. But please note that this will lead to<br>
> non-total function, e.g. it will have to return an error in case of call<br>
> with Nothing, so you should avoid writing and using functions like this.<br>
<br>
</span>A tiny nitpick: you can get a total function if you return a default<br>
value instead of erroring out.<br>
<span class=""><br></span></blockquote><div><br></div><div>What default value would you return for the function `Maybe a -> a`?</div><div><br></div><div>- Adam</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
>> Sometimes IO do something and return something, i wonder if the return<br>
>> type, for example is IO Int means it will return an int, could i purely<br>
>> fetch the int?<br>
<br>
</span>The IO in IO Int means that instead of just returning an Int, a<br>
computation may produce a side-effect (like writing a string to standard<br>
output).  Since reasoning about code without side-effects is much<br>
simpler, you want to separate it from impure code.  That's what IO is<br>
for.  Once you're inside IO, you're dealing with impure code, so you<br>
want to keep track of things that rely on it.  You can't* and don't want<br>
to escape.<br>
<br>
* As Konstantine points out, there are legitimate cases for using<br>
  unsafePerformIO, like writing an FFI binding to a pure function.<br>
  Haskell type system can't see whether the function in question is pure<br>
  or not, so it's tagged with IO.  However, if you know that it's pure,<br>
  you can explicitly state that by using unsafePerformIO.<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" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div></div>