Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Recurisive foldable... more or less
{-# 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
You can’t perform that action at this time.