Monday, April 16, 2012

Haskell (:) and (++) differences

I m sorry for a question like this. But i m not too sure about the difference of : and ++ operator in haskell.



x:y:[] = [x,y]


also



[x] ++ [y] = [x,y]


as for the reverse function which arose this question for me,



reverse ::[a]->[a]
reverse [] = []
reverse (x:xs) = reverse(xs)++[x]


why doenst the following work?



reversex ::[Int]->[Int]
reversex [] = []
reversex (x:xs) = reversex(xs):x:[]


giving a type error.





No comments:

Post a Comment