aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/abstract/comonad/cofree.lux
blob: 096a48feb80f83175e658b9f4e7e3e68199c0b06 (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: #export (CoFree F a)
  {#.doc (doc "The CoFree CoMonad.")}
  [a (F (CoFree F a))])

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

(implementation: #export (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)]))