From 6a0d7f5c434c3564d0119befb6799fd77581050a Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Fri, 3 Jan 2025 11:01:20 -0800 Subject: Initial --- ch07_07.1-iii.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ch07_07.1-iii.hs (limited to 'ch07_07.1-iii.hs') diff --git a/ch07_07.1-iii.hs b/ch07_07.1-iii.hs new file mode 100644 index 0000000..1285fd9 --- /dev/null +++ b/ch07_07.1-iii.hs @@ -0,0 +1,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 -- cgit v1.2.1