diff options
Diffstat (limited to 'stdlib/source/lux/abstract')
-rw-r--r-- | stdlib/source/lux/abstract/comonad.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/abstract/comonad/cofree.lux | 27 |
2 files changed, 27 insertions, 4 deletions
diff --git a/stdlib/source/lux/abstract/comonad.lux b/stdlib/source/lux/abstract/comonad.lux index 0722d7a1b..94b3d06c8 100644 --- a/stdlib/source/lux/abstract/comonad.lux +++ b/stdlib/source/lux/abstract/comonad.lux @@ -22,10 +22,6 @@ (-> (w a) (w (w a)))) split)) -(type: #export (CoFree F a) - {#.doc "The CoFree CoMonad."} - [a (F (CoFree F a))]) - (macro: #export (be tokens state) {#.doc (doc "A co-monadic parallel to the 'do' macro." (let [square (function (_ n) (* n n))] diff --git a/stdlib/source/lux/abstract/comonad/cofree.lux b/stdlib/source/lux/abstract/comonad/cofree.lux new file mode 100644 index 000000000..eadfa788f --- /dev/null +++ b/stdlib/source/lux/abstract/comonad/cofree.lux @@ -0,0 +1,27 @@ +(.module: + [lux #*] + [// (#+ CoMonad) + [// + [functor (#+ Functor)]]]) + +(type: #export (CoFree F a) + {#.doc "The CoFree CoMonad."} + [a (F (CoFree F a))]) + +(structure: #export (functor dsl) + (All [F] (-> (Functor F) (Functor (CoFree F)))) + + (def: (map f [head tail]) + [(f head) (:: dsl map (map f) tail)])) + +(structure: #export (comonad dsl) + (All [F] (-> (Functor F) (CoMonad (CoFree F)))) + + (def: &functor (..functor dsl)) + + (def: (unwrap [head tail]) + head) + + (def: (split [head tail]) + [[head tail] + (:: dsl map split tail)])) |