aboutsummaryrefslogtreecommitdiff
path: root/ch10_10.2-i.hs
blob: a8f1d2099c5c27c7219a357d528bfd94bf7704c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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