Skip to content

Instantly share code, notes, and snippets.

@xrl
Created April 21, 2011 07:45
Show Gist options
  • Save xrl/933938 to your computer and use it in GitHub Desktop.
Save xrl/933938 to your computer and use it in GitHub Desktop.
Flattening a list...
module Flatten where
data NestedList a = Elem a | List [NestedList a]
flatten :: NestedList a -> [a]
flatten (Elem x) = [x]
flatten (List x) = concatMap flatten x
Prelude> :l Flatten
[1 of 1] Compiling Flatten ( Flatten.hs, interpreted )
Ok, modules loaded: Flatten.
*Flatten> flatten [1,2,3]
<interactive>:1:9:
Couldn't match expected type `NestedList a0'
with actual type `[t0]'
In the first argument of `flatten', namely `[1, 2, 3]'
In the expression: flatten [1, 2, 3]
In an equation for `it': it = flatten [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment