Skip to content

Instantly share code, notes, and snippets.

@kuribas
Last active February 12, 2019 21:13
Show Gist options
  • Select an option

  • Save kuribas/244c3d9958e645ea7f12ac9ea8eed010 to your computer and use it in GitHub Desktop.

Select an option

Save kuribas/244c3d9958e645ea7f12ac9ea8eed010 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveFunctor #-}
module Test where
import Data.Functor.Foldable
import Control.Monad.Free
import qualified Control.Monad.Trans.Free as T
data Tree t = Tree t t
deriving Functor
treeHeight :: (Free Tree a) -> Int
treeHeight = cata heightAlg where
heightAlg (T.Pure _) = 1
heightAlg (T.Free (Tree a b)) = max a b + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment