From 6a0d7f5c434c3564d0119befb6799fd77581050a Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Fri, 3 Jan 2025 11:01:20 -0800 Subject: Initial --- ch10_10.1-i.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ch10_10.1-i.hs (limited to 'ch10_10.1-i.hs') diff --git a/ch10_10.1-i.hs b/ch10_10.1-i.hs new file mode 100644 index 0000000..d76160f --- /dev/null +++ b/ch10_10.1-i.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE FunctionalDependencies #-} + +-- Exercise 10.1-i +-- Defunctionalize `listToMaybe :: [a] -> Maybe a`. +newtype ListToMaybe a = ListToMaybe [a] + +class Eval l t | l -> t where + eval :: l -> t + +instance Eval (ListToMaybe a) (Maybe a) where + eval (ListToMaybe []) = Nothing + eval (ListToMaybe (x : _)) = Just x -- cgit v1.2.1