@@ -1,4 +1,10 @@
1−module TypeFun.Data.Maybe where
1+module TypeFun.Data.Maybe
3import GHC.Exts
9import GHC.Exts
@@ -8,7 +14,6 @@ type family MaybeCase (a :: Maybe k)
8 MaybeCase 'Nothing nothing just = nothing
14 MaybeCase 'Nothing nothing just = nothing
9 MaybeCase ('Just k) nothing just = just k
15 MaybeCase ('Just k) nothing just = just k
12type family NothingToConstr (a :: Maybe k) (c :: Constraint) :: Constraint where
17type family NothingToConstr (a :: Maybe k) (c :: Constraint) :: Constraint where
13 NothingToConstr 'Nothing c = c
18 NothingToConstr 'Nothing c = c
14 NothingToConstr ('Just a) c = ()
19 NothingToConstr ('Just a) c = ()
@@ -17,6 +22,7 @@ type family JustToConstr (a :: Maybe k) (c :: Constraint) :: Constraint where
17 JustToConstr 'Nothing c = ()
22 JustToConstr 'Nothing c = ()
18 JustToConstr ('Just a) c = c
23 JustToConstr ('Just a) c = c
25+-- | Like 'catMaybes' for type lists
20type family CatMaybes (l :: [Maybe k]) :: [k] where
26type family CatMaybes (l :: [Maybe k]) :: [k] where
21 CatMaybes '[] = '[]
27 CatMaybes '[] = '[]
22 CatMaybes (('Just a) ': as) = a ': (CatMaybes as)
28 CatMaybes (('Just a) ': as) = a ': (CatMaybes as)