Created
April 21, 2011 07:45
-
-
Save xrl/933938 to your computer and use it in GitHub Desktop.
Flattening a list...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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