aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/abstract/comonad/free.lux
blob: 2e7e7cf1c9906ccd8261767606aa0af224923ca5 (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
(.using
 [library
  [lux (.except)]]
 [// (.only CoMonad)
  [//
   [functor (.only Functor)]]])

(type: .public (Free F a)
  [a (F (Free F a))])

(def .public (functor dsl)
  (All (_ F) (-> (Functor F) (Functor (Free F))))
  (implementation
   (def (each f [head tail])
     [(f head) (at dsl each (each f) tail)])))

(def .public (comonad dsl)
  (All (_ F) (-> (Functor F) (CoMonad (Free F))))
  (implementation
   (def functor (..functor dsl))

   (def (out [head tail])
     head)

   (def (disjoint [head tail])
     [[head tail]
      (at dsl each disjoint tail)])))