<div dir="ltr">On Sun, Jun 2, 2013 at 7:22 PM, Ting Lei <span dir="ltr">&lt;<a href="mailto:tinlyx@gmail.com" target="_blank">tinlyx@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>In particular, I wanted to avoid having an IO in the return type because introducing the impurity<br></div>
<div>(by that I mean the IO monad) for this simple task is logically unnecessary. All examples involing</div></blockquote><div><br></div><div style>Anything that comes into or goes out of a Haskell program is in IO, period. If you have an FFI function which is guaranteed to not change anything but its parameters and those only in a pure way, then you can use unsafeLocalState to &quot;hide&quot; the IO; but claiming that when it&#39;s not true can lead to problems ranging from incorrect results to core dumps, so don&#39;t try to lie about it.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div> a C string I have seen so far involve returning an IO something or Ptr which cannot be converted back to a pure String.</div></blockquote><div><br></div><div style>Haskell String-s are *not* C strings. Not even slightly. C cannot work with Haskell&#39;s String type directly at all. Some kind of marshaling is absolutely necessary; there are functions in Foreign.Marshal.String that will marshal Haskell String-s to and from C strings.</div>
<div style><br></div><div style>(String is a linked list of Char, which is also not a C char; it is a constructor and a machine word large enough to hold a Unicode codepoint. And because Haskell is non-strict, any part of that linked list can be an unevaluated thunk which requires forcing the evaluation of arbitrary Haskell code elsewhere to &quot;reify&quot; the value; this obviously cannot be done in the middle of random C code, so it must be done during marshaling.)</div>
<div><br></div></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>
<div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>