I need to implement a split function in haskell where user gives the as a example input
splitx [1,2,3,4,5,6] 3
should output -> [1,2,3]
splitx::[Int]->Int->[Int]
splitx [] 0 = []
splitx (x:xs) n = x: splitx xs (n-1)
i wrote the following function but it gives a error
Non-exhaustive patterns in function Main.splitx
just tell me where am i wrong ?
If you want to return the first n elements:
you have no pattern match for input where n=0 and list is not empty:
Note: specify the type to be generic so it works not only with Ints: