How to use generics in Haskell -
i'm trying wrap head around generics in haskell. issue created concatenate function takes list of strings , returns giant string.
concatenate:: [string] -> string concatenate xs = foldl (\acc x -> acc ++ x) [] xs
but i'd instead of list of strings, use list of anything. can strings, can ints.
concatenate ["phil", "is"]
generates "philis" while
concatenate [[1,2],[3,4]]
generates [1,2,3,4].
i've found
concatenate:: [a] -> concatenate xs = foldl (\acc x -> acc ++ x) [] xs
does not work , i'm not sure why. isn't way haskell works, whatever type is, output well? or issue second half not allowing work function types?
keep in mind string
alias [char]
.
what intended this:
concatenate:: [[a]] -> [a]
Comments
Post a Comment