There are a lot of things there,
nthel :: Int -> [Int] -> Int
technically correct, really we want
nthel :: Int -> [a] -> a
Therefore, we can use this in lists of anything (optional)
nthel n xs = 0
What you just said is "No matter what you give nthel return 0". which is clearly wrong.
let xsxs = ...
This is simply not a legitimate haskell. let ... in ... is an expression, it cannot be used to fill.
From there, I'm not quite sure what this should do.
Perhaps this will help put you on the right track.
nthelem n [] = <???> -- error case, empty list nthelem 0 xs = head xs nthelem n xs = <???> -- recursive case
Try filling out <???> your best guess, and I will be happy to help from there.
Alternatively, you can use the Haskell pattern matching syntax. I will explain how you can do this with lists here .
This changes our value higher to
nthelem n [] = <???> -- error case, empty list nthelem 0 (x:xs) = x --bind x to the first element, xs to the rest of the list nthelem n (x:xs) = <???> -- recursive case
This is convenient as it negates the need to use explicit head and tail s.
jozefg
source share