Look also at <a href="http://hackage.haskell.org/package/safe">safe package</a><br><br><div class="gmail_quote">2012/3/13 Chris Wong <span dir="ltr"><<a href="mailto:chrisyco%2Bhaskell-cafe@gmail.com">chrisyco+haskell-cafe@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith <<a href="mailto:cdsmith@gmail.com">cdsmith@gmail.com</a>> wrote:<br>
> On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees <<a href="mailto:k.clees@web.de">k.clees@web.de</a>> wrote:<br>
>> Now my function looks like this:<br>
>><br>
>> tmp:: [(Int, Int)] -> Int -> (Int, Int)<br>
>> tmp [] y = (0,0)<br>
>> tmp xs y = xs !! (y-1)<br>
><br>
> Just a warning that this will still crash if the list is non-empty by<br>
> the index exceeds the length. That's because your function is no<br>
> longer recursive, so you only catch the case where the top-level list<br>
> is empty. The drop function doesn't crash when dropping too many<br>
> elements though, so you can do this and get a non-recursive function<br>
> that's still total:<br>
><br>
> tmp :: [(Int,Int)] -> Int -> (Int, Int)<br>
> tmp xs y = case drop (y-1) xs of<br>
> [] -> (0,0)<br>
> Just (x:_) -> x<br>
<br>
</div>That last line should be<br>
<br>
(x:_) -> x<br>
<br>
without the "Just". Hopefully that'll save a bit of confusion.<br>
<span class="HOEnZb"><font color="#888888"><br>
Chris<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> --<br>
> Chris Smith<br>
><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>