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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -