lundi 20 novembre 2017

Haskell error "parse error on input ‘if'"

I got a question regarding Haskell, I tried to make a function to half an even number only in a list and return the final list with only the even number(s) got modified(got halved) with the rest of the element remained untouched.

But when I try to compile my code, I gave an error saying that "error: parse error on input ‘if'" and I couldn't find the solution for it.

halfEvens :: [ Int ] -> [ Int ]
halfEvens xs = [x|x<-xs]
                if x mod 2 == 0
                the x = x / 2
                else
                x = x

Aucun commentaire:

Enregistrer un commentaire