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