on ccddf7e help sign in
32 lines 934 B history raw
1module TypeFun.Data.Maybe
2 ( MaybeCase
3 , NothingToConstr
4 , JustToConstr
5 , CatMaybes
6 , FromJust
7 ) where
9import GHC.Exts
11type family MaybeCase (a :: Maybe k)
12 (nothing :: r)
13 (just :: k -> r) :: r where
14 MaybeCase 'Nothing nothing just = nothing
15 MaybeCase ('Just k) nothing just = just k
17type family NothingToConstr (a :: Maybe k) (c :: Constraint) :: Constraint where
18 NothingToConstr 'Nothing c = c
19 NothingToConstr ('Just a) c = ()
21type family JustToConstr (a :: Maybe k) (c :: Constraint) :: Constraint where
22 JustToConstr 'Nothing c = ()
23 JustToConstr ('Just a) c = c
25-- | Like 'catMaybes' for type lists
26type family CatMaybes (l :: [Maybe k]) :: [k] where
27 CatMaybes '[] = '[]
28 CatMaybes (('Just a) ': as) = a ': (CatMaybes as)
29 CatMaybes ('Nothing ': as) = CatMaybes as
31type family FromJust (a :: Maybe k) :: k where
32 FromJust ('Just a) = a