Last active
May 10, 2018 05:05
-
-
Save bradparker/751656d85246e5a9ec1314305dd905fc to your computer and use it in GitHub Desktop.
Recurisive foldable... more or less
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
| {-# LANGUAGE DeriveFoldable #-} | |
| module Main where | |
| import Data.Map (Map) | |
| import qualified Data.Map as Map | |
| import Data.Foldable | |
| data Object a | |
| = Value a | |
| | Dictionary (Map String (Object a)) | |
| deriving (Show, Foldable) | |
| obj :: Object String | |
| obj = Dictionary (Map.fromList | |
| [ ( "Foo" | |
| , Dictionary (Map.fromList | |
| [ ("Bar", Value "Baz") | |
| , ("Qux", Dictionary (Map.fromList [("Qux", Value "BAHHHH")])) | |
| ]) | |
| ) | |
| ]) | |
| main :: IO () | |
| main = print (foldr (:) [] obj) | |
| -- outputs ["Baz","BAHHHH"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment