I have an exercise to do, however and since I'm new to the language, I can not find any way on how to do it.
I have this function "repeated" that's defined as such, given under this paragraph. It receives a list of Int and gives back a Bool value. It's supposed to check if a list has any repeated elements. If so, it's TRUE, if not, it's false. There is one extra: I have to define the function by recursion, so it has to be a recursive function. Would appreciate any help.
repeated :: [Int] -> Bool
EDIT1: So far, I've only managed to succeed with this amount of code
repeated :: [Int] -> Bool
repeated [] = False
repeated (h:t) =
Which gives me back the empty list, only. The rest, I've not been able to figure out so far...
EDIT2: Forgot about the singular lists... Also, possible answer?
repeated :: [Int] -> Bool
repeated [] = False
repeated [_] = False
repeated (h:t) = if elem h t then True
else repeated t
That's pretty much it. I've compiled the .hs and it worked perfectly. Thank you all for the suggestions and hints! :)
nub
:repeated xs = xs == nub xs
? – Bakuriuelem
function may help. – BaderousOrd a
which has been sorted. – Matthew Walton