Browse Source

Problem 07

completed
Craige McWhirter 9 months ago
parent
commit
d616e8e377
Signed by: craige GPG Key ID: 7DBA9F5689EFB6AA
  1. 14
      flatten.hs

14
flatten.hs

@ -0,0 +1,14 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-orphans #-}
-- Flatten a nested list structure.
-- Transform a list, possibly holding lists as elements into a `flat' list by
-- replacing each list with its elements (recursoively).
-- data: defines a new data type (GADT)
data NestedList a = Elem a | List [NestedList a]
flatten :: NestedList a -> [a]
flatten (Elem x) = [x]
flatten (List x) = concatMap flatten x
Loading…
Cancel
Save