Skip to content

Instantly share code, notes, and snippets.

@probablytom
Created May 7, 2017 13:42
Show Gist options
  • Save probablytom/62e13099ca05c1feb1f5ecce59f09d81 to your computer and use it in GitHub Desktop.
Save probablytom/62e13099ca05c1feb1f5ecce59f09d81 to your computer and use it in GitHub Desktop.

I actually used this in my treezip submission to get my zipping function into the tree. If you're looking for a more complicated example, fmap can let you apply functions in this sort of way also:

instance Functor Tree where
  fmap f Leaf = Leaf
  fmap f (Node elem left right) = Node newelem newleft newright
    where newelem  = f elem
          newleft  = fmap f left
          newright = fmap f right

That's not important, so leave it if it makes you uncomfortable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment