Created
June 23, 2014 21:49
-
-
Save fronx/0fe9124f5e1236bc84ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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 NestedLists where | |
data NestedList a = Nest [NestedList a] | Item a | |
deriving Show | |
nestedList = Nest [ Item 1 | |
, Item 2 | |
, Nest [ Item 3 | |
, Nest [ Item 4 | |
, Item 5 | |
] | |
, Item 6 | |
] | |
] | |
instance Functor NestedList where | |
fmap f (Item x) = Item (f x) | |
fmap f (Nest nest) = Nest ((fmap . fmap) f nest) | |
main = do | |
print $ fmap (*2) nestedList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment