Skip to content

Instantly share code, notes, and snippets.

@hrb90
Last active September 1, 2017 16:23
Show Gist options
  • Save hrb90/99d50d1416e5b93436f23981814ba77b to your computer and use it in GitHub Desktop.
Save hrb90/99d50d1416e5b93436f23981814ba77b to your computer and use it in GitHub Desktop.
i is a haskell programmer
{-# LANGUAGE DeriveFunctor #-}
data MaybePair a = Pair (Maybe a) (Maybe a)
deriving (Eq, Show, Functor)
data BinaryTree a =
Node a (MaybePair (BinaryTree a))
deriving (Eq, Show)
invert :: BinaryTree a -> BinaryTree a
invert (Node x children) = Node x $ invertPair $ invert <$> children
where invertPair (Pair left right) = Pair right left
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment