on master help sign in
Added cast instances both directions between Maybe and Monoids.
f57a454Leif Warner
lib/Prelude/Maybe.idr+9
@@ -2,6 +2,7 @@ module Prelude.Maybe
2
2
3import Builtins
3import Builtins
4import Prelude.Algebra
4import Prelude.Algebra
5+import Prelude.Cast
5
6
6%access public
7%access public
7%default total
8%default total
@@ -58,3 +59,11 @@ instance (Semigroup a) => Semigroup (Maybe a) where
58
59
59instance (Monoid a) => Monoid (Maybe a) where
60instance (Monoid a) => Monoid (Maybe a) where
60 neutral = Nothing
61 neutral = Nothing
62+
63+
64+instance (Monoid a, Eq a) => Cast a (Maybe a) where
65+ cast x = if x == neutral then Nothing else Just x
66+
67+instance (Monoid a) => Cast (Maybe a) a where
68+ cast Nothing = neutral
69+ cast (Just x) = x