aboutsummaryrefslogtreecommitdiff
path: root/ch07_07.1-iii.hs
blob: 1285fd9158be5956a991ee0cdfca77829e0f4ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
-- Exercise 7.1-iii
-- Write the `Show` instance for `HasShow` in terms of `elimHasShow`.
data HasShow where
  HasShow :: Show t => t -> HasShow

elimHasShow :: (forall a. Show a => a -> r) -> HasShow -> r
elimHasShow f (HasShow a) = f a

-- This version also prepends the `HasShow` name to the result of `show`:
instance Show HasShow where
  show = mappend "HasShow " . elimHasShow show