on master help sign in
Added cast instances both directions between Maybe and Monoids.
commitf57a454790cad9bb127bef9ac0a30b245c2936b4 authorLeif Warner <leif@janrain.com> dateMon 14 Jan 2013, 01:23 (14 years ago) parent6be4eb2
1 file changed+9
lib/Prelude/Maybe.idr+9
lib/Prelude/Maybe.idr+9
@@ -2,6 +2,7 @@ module Prelude.Maybe
22
33import Builtins
44import Prelude.Algebra
5+import Prelude.Cast
56
67%access public
78%default total
@@ -58,3 +59,11 @@ instance (Semigroup a) => Semigroup (Maybe a) where
5859
5960instance (Monoid a) => Monoid (Maybe a) where
6061 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