Foldable and traversable

Run Settings
LanguageHaskell
Language Version
Run Command
{-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveTraversable #-} module Main ( main ) where data Tree a = a :<<: [Tree a] deriving (Show, Functor, Foldable, Traversable) main :: IO () main = do putStr "Example tree: " print example putStr "\nEach element transformed (fmap): " print (fmap negate example) putStr "\nAll elements summed (foldl): " print (foldl (+) 0 example) putStr "\nAll elements printed, then the result of that printed (traverse): " print =<< traverse print example where example :: Tree Int example = 1 :<<: [2 :<<: [], 3 :<<: [4 :<<: [], 5 :<<: []], 6 :<<: []]
Editor Settings
Theme
Key bindings
Full width
Lines