aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/comonad/free.lux
blob: f089b22313816cf53ebf9f3488a9a4e80827380f (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(.require
 [library
  [lux (.except)
   [abstract
    [functor (.only Functor)]
    [comonad (.only CoMonad)]
    [\\specification
     ["$[0]" functor (.only Injection Comparison)]
     ["$[0]" comonad]]]
   [control
    ["//" continuation]]
   [data
    [collection
     ["[0]" list]
     ["[0]" stream (.only Stream) (.use "[1]#[0]" comonad)]]]
   [math
    ["[0]" random]]
   [test
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" /]])

(def (injection value)
  (Injection (/.Free Stream))
  [value (stream#each injection (stream.repeated value))])

(def (interpret [head tail])
  (All (_ a) (-> (/.Free Stream a) (Stream a)))
  (|> tail
      (stream#each (at (/.comonad stream.functor) out))
      [head]
      //.pending))

(def comparison
  (Comparison (/.Free Stream))
  (function (_ == left right)
    (at (list.equivalence ==) =
        (stream.first 100 (..interpret left))
        (stream.first 100 (..interpret right)))))

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Free])
      (all _.and
           (_.for [/.functor]
                  ($functor.spec ..injection ..comparison (is (Functor (/.Free Stream))
                                                              (/.functor stream.functor))))
           (_.for [/.comonad]
                  ($comonad.spec ..injection ..comparison (is (CoMonad (/.Free Stream))
                                                              (/.comonad stream.functor))))
           )))