@@ -24,7 +24,8 @@ data Tree a w = Leaf a
24 | WithWeight (Tree a w) w
24 | WithWeight (Tree a w) w
25 deriving (Show, Eq, Generic)
25 deriving (Show, Eq, Generic)
27−deriving instance Bifunctor Tree
27+instance Bifunctor Tree where
29mytree :: Tree Int Int
30mytree :: Tree Int Int
30mytree = Fork (WithWeight (Leaf 42) 1)
31mytree = Fork (WithWeight (Leaf 42) 1)
@@ -34,12 +35,13 @@ mytreeBimapped :: Tree Int String
34mytreeBimapped = Fork (WithWeight (Leaf 84) "1")
35mytreeBimapped = Fork (WithWeight (Leaf 84) "1")
35 (WithWeight (Fork (Leaf 176) (Leaf 74)) "2")
36 (WithWeight (Fork (Leaf 176) (Leaf 74)) "2")
37−-- Derivable Bifunctor
38+--------------------------------------------------------------------------------
38class Bifunctor p where
40class Bifunctor p where
39 bimap :: (a -> c) -> (b -> d) -> p a b -> p c d
41 bimap :: (a -> c) -> (b -> d) -> p a b -> p c d
41− default bimap ::
43+gbimap ::
42 ( HasParam 0 (p a b) (p a d) b d
44 ( HasParam 0 (p a b) (p a d) b d
43 , HasParam 1 (p a d) (p c d) a c
45 , HasParam 1 (p a d) (p c d) a c
44 ) => (a -> c) -> (b -> d) -> p a b -> p c d
46 ) => (a -> c) -> (b -> d) -> p a b -> p c d
45− bimap f g s = s & param @0 %~ g & param @1 %~ f
47+gbimap f g s = s & param @0 %~ g & param @1 %~ f