]> gitweb @ CieloNegro.org - hs-rrdtool.git/blobdiff - Types/Data/Maybe.hs
type-level maps and maybes
[hs-rrdtool.git] / Types / Data / Maybe.hs
diff --git a/Types/Data/Maybe.hs b/Types/Data/Maybe.hs
new file mode 100644 (file)
index 0000000..997c93b
--- /dev/null
@@ -0,0 +1,42 @@
+{-# LANGUAGE
+  EmptyDataDecls,
+  TypeFamilies
+  #-}
+module Types.Data.Maybe
+    ( Maybe
+    , Nothing
+    , Just
+
+    , IsNothing
+    , IsJust
+
+    , FromJust
+    , FromMaybe
+    )
+    where
+
+import Prelude ()
+import Types.Data.Bool
+
+
+data Nothing
+data Just a
+
+class    Maybe a
+instance Maybe Nothing
+instance Maybe (Just a)
+
+type family   IsNothing m
+type instance IsNothing Nothing  = True
+type instance IsNothing (Just a) = False
+
+type family   IsJust m
+type instance IsJust Nothing  = False
+type instance IsJust (Just a) = True
+
+type family   FromJust m
+type instance FromJust (Just a) = a
+
+type family   FromMaybe a m
+type instance FromMaybe a Nothing   = a
+type instance FromMaybe a (Just a') = a'