diff options
Diffstat (limited to 'stdlib/source/lux/abstract/functor.lux')
-rw-r--r-- | stdlib/source/lux/abstract/functor.lux | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/stdlib/source/lux/abstract/functor.lux b/stdlib/source/lux/abstract/functor.lux index a259673d4..a9fc6796c 100644 --- a/stdlib/source/lux/abstract/functor.lux +++ b/stdlib/source/lux/abstract/functor.lux @@ -9,11 +9,29 @@ (type: #export (Fix f) (f (Fix f))) +(type: #export (Or f g) + (All [a] (| (f a) (g a)))) + +(def: #export (sum (^open "f@.") (^open "g@.")) + (All [F G] (-> (Functor F) (Functor G) (Functor (..Or F G)))) + (structure + (def: (map f fa|ga) + (case fa|ga + (#.Left fa) + (#.Left (f@map f fa)) + + (#.Right ga) + (#.Right (g@map f ga)))))) + (type: #export (And f g) (All [a] (& (f a) (g a)))) -(type: #export (Or f g) - (All [a] (| (f a) (g a)))) +(def: #export (product (^open "f@.") (^open "g@.")) + (All [F G] (-> (Functor F) (Functor G) (Functor (..And F G)))) + (structure + (def: (map f [fa ga]) + [(f@map f fa) + (g@map f ga)]))) (type: #export (Then f g) (All [a] (f (g a)))) |