Skip to content

Instantly share code, notes, and snippets.

@fronx
Created June 23, 2014 21:49
Show Gist options
  • Save fronx/0fe9124f5e1236bc84ff to your computer and use it in GitHub Desktop.
Save fronx/0fe9124f5e1236bc84ff to your computer and use it in GitHub Desktop.
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