Look also at safe package http://hackage.haskell.org/package/safe
2012/3/13 Chris Wong chrisyco+haskell-c...@gmail.com
On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith cdsm...@gmail.com wrote:
On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees k.cl...@web.de wrote:
Now my function looks like this:
Kevin Clees k.cl...@web.de writes:
Now my function looks like this:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp [] y = (0,0)
^
tmp xs y = xs !! (y-1)
If the function returns (0,0) it will blocked by another function.
Personally, I think using special values like this is
Dear Haskell friends,
what can I do, if a function gets an empty input list? I want, that it only
returns nothing.
This is my source code:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp (x:xs) y
| y == 1 = x
| y 1 = tmp xs (y-1)
If this function gets an empty list, he throws
On Mon, Mar 12, 2012 at 2:41 PM, Kevin Clees k.cl...@web.de wrote:
what can I do, if a function gets an empty input list? I want, that it only
returns nothing.
This is my source code:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp (x:xs) y
| y == 1 = x
| y 1 = tmp xs (y-1)
It's
Oh, and just to point this out, the function you're writing already
exists in Data.List. It's called (!!). Well, except that it's zero
indexed, so your function is more like:
tmp xs y = xs !! (y-1)
___
Haskell-Cafe mailing list
Hey Chris,
thank you for your help! Your last comment with the (!!)-thing was a very good
idea!
Now my function looks like this:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp [] y = (0,0)
tmp xs y = xs !! (y-1)
If the function returns (0,0) it will blocked by another function.
If I want to
On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees k.cl...@web.de wrote:
Now my function looks like this:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp [] y = (0,0)
tmp xs y = xs !! (y-1)
Just a warning that this will still crash if the list is non-empty by
the index exceeds the length. That's
On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith cdsm...@gmail.com wrote:
On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees k.cl...@web.de wrote:
Now my function looks like this:
tmp:: [(Int, Int)] - Int - (Int, Int)
tmp [] y = (0,0)
tmp xs y = xs !! (y-1)
Just a warning that this will still crash