September 2017
Beginner to intermediate
396 pages
9h 46m
English
module Main where
import Data.Functor
import Control.Applicative
data Tree a = Leaf
| Node (Tree a) a (Tree a)
deriving (Show, Eq)
instance Functor Tree where
fmap _ Leaf = Leaf
fmap f (Node left value right) = Node (fmap f left) (f value) (fmap f right)
instance Applicative Tree where pure x = let t = Node t x t
in t (<*>) Leaf _ = Leaf (<*>) ...Read now
Unlock full access