on master help sign in
Merge pull request #153 from LeifW/monoid_maybe_casting

Added cast instances both directions between Maybe and Monoids.

commit519e34f743fc34704f9c2613c2e30ce9938df9f2 authorEdwin Brady <edwin.brady@gmail.com> dateSun 20 Jan 2013, 07:30 (14 years ago) parenta601cc6f57a454
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