aboutsummaryrefslogtreecommitdiff
path: root/ch10_10.2-i.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ch10_10.2-i.hs')
-rw-r--r--ch10_10.2-i.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/ch10_10.2-i.hs b/ch10_10.2-i.hs
new file mode 100644
index 0000000..a8f1d20
--- /dev/null
+++ b/ch10_10.2-i.hs
@@ -0,0 +1,17 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeFamilies #-}
+
+-- Exercise 10.2-i
+-- Defunctionalize `listToMaybe` at the type-level.
+
+import Data.Kind (Type)
+
+type Exp a = a -> Type
+
+type family Eval (e :: Exp a) :: a
+
+data ListToMaybe :: [a] -> Exp (Maybe a)
+
+type instance Eval (ListToMaybe '[]) = 'Nothing
+
+type instance Eval (ListToMaybe (x ': _)) = 'Just x