[Haskell-cafe] Empty Input list

Kevin Clees k.clees at web.de
Mon Mar 12 21:41:03 CET 2012

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 "Exception: sortAlgo.hs:(18,1)-(21,44): Non-exhaustive patterns in function Main.tmp"

*Main> tmp [(1,2),(3,2)] 1
*Main> tmp [(1,2),(3,2)] 2
*Main> tmp [] 1
*** Exception: sortAlgo.hs:(20,1)-(22,44): Non-exhaustive patterns in function Main.listElementIntInt

Thank you for any help !

Best regards

More information about the Haskell-Cafe mailing list