aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/abstract/comonad/cofree.lux
blob: 1431ee3cc73874424b82e3cf833aae92bee2ad9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(.module:
  [library
   [lux #*]]
  [// (#+ CoMonad)
   [//
    [functor (#+ Functor)]]])

(type: .public (CoFree F a)
  {#.doc "The CoFree CoMonad."}
  [a (F (CoFree F a))])

(implementation: .public (functor dsl)
  (All [F] (-> (Functor F) (Functor (CoFree F))))
  
  (def: (map f [head tail])
    [(f head) (\ dsl map (map f) tail)]))

(implementation: .public (comonad dsl)
  (All [F] (-> (Functor F) (CoMonad (CoFree F))))

  (def: &functor (..functor dsl))

  (def: (out [head tail])
    head)

  (def: (split [head tail])
    [[head tail]
     (\ dsl map split tail)]))