<div dir="ltr">I agree that it seems uncomfortable for a seemingly pure function to require handling exceptions in the IO monad, but if the code in question really does have the capability of raising IO exceptions, then I think it is reasonable to consider it as impure and belonging in the IO monad and that it probably should not have been given a pure type signature to start with. I&#39;d double check to see if the function in question has the capability of raising an exception in a more pure monad as per Kees&#39;s suggestion. The other option is to perform the actions I&#39;ve suggested and then wrap the whole lot in unsafePerformIO to make it pure again but with a new signature of (a -&gt; Either YourException b), however that just makes me feel even more queazy...<div>

<br></div><div style>Other than that, I guess we&#39;d need a snippet of the code and what libraries are being used in order to provide better help.</div><div><br></div><div style>Good luck!</div></div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Mon, Jul 15, 2013 at 4:07 AM, Kees Bleijenberg <span dir="ltr">&lt;<a href="mailto:k.bleijenberg@lijbrandt.nl" target="_blank">k.bleijenberg@lijbrandt.nl</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div lang="NL" link="blue" vlink="purple"><div><p class="MsoNormal"><span lang="EN-US" style="color:#1f497d">Lyndon,<u></u><u></u></span></p><div class="im"><div><p class="MsoNormal"><span lang="EN-US" style="color:#1f497d">You wrote:<br>

</span><span lang="EN-US">You can turn anything into an IO action with return, or you could catch the exception at a level where you are performing IO. Would this be what you&#39;re after?<u></u><u></u></span></p></div></div>

<div><p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="color:#1f497d">Wait until you perform IO, seems quit uneasy to me and why? Converting a string to a typeable is not a IO action. Problem is that this function lives in a dll. The IO is done by the calling program (not a Haskell program). The function is not in a monad, it is a pure function. So I think I can’t do a return.<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p>

<span class="HOEnZb"><font color="#888888"><p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="color:#1f497d">Kees</span><span lang="EN-US" style="color:#1f497d"><u></u><u></u></span></p></font></span><div class="im">

<div><div><div><p class="MsoNormal"><span lang="EN-US">On Sun, Jul 14, 2013 at 7:47 PM, Kees Bleijenberg &lt;<a href="mailto:k.bleijenberg@lijbrandt.nl" target="_blank">k.bleijenberg@lijbrandt.nl</a>&gt; wrote:<span style="color:#1f497d"><u></u><u></u></span></span></p>

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span lang="EN-US">The app I’am working on, converts a jsonString to another string encoding. <u></u><u></u></span></p><p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt">

<span lang="EN-US">The function I want to write is  jsonString -&gt; (encoding, errorMsg)  so String-&gt; (String, String) <u></u><u></u></span></p><p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span lang="EN-US">For this purpose I have a typeable datastructure Glass. Because it is typeable I can do (decodeJSON jsonString) :: Glass<u></u><u></u></span></p>

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span lang="EN-US">But sometimes the jsonString is not valid (misformed or wrong fields). decodeJSON then throws a exception.  I want to<u></u><u></u></span></p>

<p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span lang="EN-US">catch that exection and transform the result to something like (“” , theErrorMsg). Unfortunately all catch functions want IO parameters. <u></u><u></u></span></p>

<p class="MsoNormal"><span lang="EN-US">What can I do?<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="color:#888888"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="color:#888888">Kees<u></u><u></u></span></p>

<p class="MsoNormal"><span lang="EN-US" style="color:#888888"> <u></u><u></u></span></p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US"><br>_______________________________________________<br>

Beginners mailing list<br><a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><u></u><u></u></span></p>

</div><p class="MsoNormal" style="margin-bottom:0cm;margin-bottom:.0001pt"><span lang="EN-US"><u></u> <u></u></span></p></div></div></div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>