<p dir="ltr">Good clarification.</p>
<p dir="ltr">Cheers,<br>
Darren</p>
<div class="gmail_quote">On Nov 1, 2015 01:09, "Erik Hesselink" <<a href="mailto:hesselink@gmail.com">hesselink@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think you misinterpreted that answer. As far as I'm aware, `error`<br>
(except in its type) is no less reasonable than other exceptions, and<br>
you can catch it in IO. So as long as you run a test in IO, you can<br>
test for the call to `error` (as Joachim showed in another reply).<br>
<br>
Regards,<br>
<br>
Erik<br>
<br>
On 31 October 2015 at 11:40, Darren Grant <<a href="mailto:dedgrant@gmail.com">dedgrant@gmail.com</a>> wrote:<br>
> Unfrotunately the answer to this is not simple:<br>
><br>
> <a href="http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function</a><br>
><br>
> 'error' more or less terminates the program in an unreasonable way.<br>
><br>
> It would be preferable for f2 to result in a type that can contain the error<br>
> result to be parsed.<br>
><br>
> Cheers,<br>
> Darren<br>
><br>
> On Oct 31, 2015 21:16, "Roelof Wobben" <<a href="mailto:r.wobben@home.nl">r.wobben@home.nl</a>> wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> I have made this exercise which can be found at the Craft of Functional<br>
>> Programming book.<br>
>><br>
>> -- exercise 32<br>
>><br>
>> -- Suppose we have to raise 2 to the power n. If n is even, 2*m say, then<br>
>> -- 2n = 22*m = (2m)2<br>
>> -- If n is odd, 2*m+l say, then<br>
>> -- 2n = 22*m+l = (2n)2*2<br>
>> -- Give a recursive function to compute 2n which uses these insights.<br>
>><br>
>> f2 :: Integer -> Integer<br>
>> f2 n<br>
>> | n < 0 = error "This will only run for positive numbers"<br>
>> | n == 0 = 1<br>
>> | even n = f2 ( n `div` 2) ^ 2<br>
>> | odd n = (f2 ( n `div` 2) ^ 2) * 2<br>
>><br>
>><br>
>> Now I have to make Hunit tests for it,<br>
>><br>
>> But is there a way I can test if the error message is shown when a<br>
>> negative number is being used ?<br>
>><br>
>> Roelof<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>
><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>