... | ... | @@ -70,7 +70,7 @@ derive Functor for the last position: |
|
|
data S a b = S1 [b] | S2 (a, T a b)
|
|
|
instance Functor (S a) where
|
|
|
fmap f (S1 bs) = S1 (fmap f bs)
|
|
|
fmap f (S2 (p,q)) = S2 (a, fmap f q)
|
|
|
fmap f (S2 (p,q)) = S2 (p, fmap f q)
|
|
|
|
|
|
However, we have special cases for
|
|
|
- tuples
|
... | ... | @@ -652,4 +652,4 @@ This definition ensures that `bifoldMap id = foldMap` for a derived `Foldable` i |
|
|
|
|
|
Deriving `Eq1/2`, `Ord1/2`, and `Show1/2` could be done in a very similar way to deriving `Foldable/Bifoldable`. For instance, you can substitute in `liftEq`/`liftEq2` in place of `foldMap`/`bifoldMap` in the above algorithm and have a sensible way to generate `liftEq`/`liftEq2` expressions. In addition, `Eq1/2`, `Ord1/2`, and `Show1/2` can all be derived for GADTs as well.
|
|
|
|
|
|
`Read1/2` could not be derived for GADTs, since it mentions type variables in the return types of its methods, but it could still be derived using the same principles as deriving `Foldable`/`Bifoldable`. |
|
|
`Read1/2` could not be derived for GADTs, since it mentions type variables in the return types of its methods, but it could still be derived using the same principles as deriving `Foldable`/`Bifoldable`. |
|
|
\ No newline at end of file |