I want to create a function, let's call it altHead, that takes 2 variables and outputs a variable such that:
a -> [a] -> a
I want to call it like this:
altHead 3 [1,2,3,4]
What it should do is to look at the first variable, and the list. If the list is empty, then return the first var's value; otherwise, return the list.
In this case, I've written the following code.
altHead :: a -> [a] -> a
altHead (x:xs) = if null[xs] then [x] else [xs]
However, I believe x:xs only looks through the list.
I'm a bit stuck as to how to change this so that it looks at the first value as well, and how to include the first value in the function.
(x:xs)doesn't bind two arguments, it binds the head and tail of a single argument that must be a list.altHead a (x:xs) =