wiki:Functions/Concat

concat

concat :: [[a]] -> [a]
concat []       =  []
concat (xs:xss) = xs ++ concat xss

with the property (associativity)

concat (xss ++ yss) = (concat xss) ++ (concat yss)

or just

concat :: [[a]] -> [a]
concat = foldr (++) []

or

(define (concat . xss)
  (foldl append '() xss))

no need to (reverse xss) here since (++) or append is an associative operation with '() as the unit.

Last modified 3 years ago Last modified on May 22, 2018, 1:52:54 PM
Note: See TracWiki for help on using the wiki.