Re: [Haskell-cafe] Empty Input list

2012-03-13 Thread Ketil Malde
Kevin Clees 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 a cod

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Dmitry Olshansky
Look also at safe package 2012/3/13 Chris Wong > On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith wrote: > > On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees wrote: > >> Now my function looks like this: > >> > >> tmp:: [(Int, Int)] -> Int -> (Int, Int) > >> t

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Chris Wong
On Tue, Mar 13, 2012 at 12:24 PM, Chris Smith wrote: > On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees 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 n

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Chris Smith
On Mon, Mar 12, 2012 at 3:14 PM, Kevin Clees 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 because your f

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Kevin Clees
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 u

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Chris Smith
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 Haskell-Cafe@haskell.or

Re: [Haskell-cafe] Empty Input list

2012-03-12 Thread Chris Smith
On Mon, Mar 12, 2012 at 2:41 PM, Kevin Clees 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 not

[Haskell-cafe] Empty Input list

2012-03-12 Thread Kevin Clees
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 "Exc