aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/abstract/comonad/cofree.lux
blob: 8a089c5337fbc1926f00104d1bb31ebdd6121607 (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [functor (#+ Functor)]
    [comonad (#+ CoMonad)]
    {[0 #spec]
     [/
      ["$." functor (#+ Injection Comparison)]
      ["$." comonad]]}]
   [control
    ["//" continuation]]
   [data
    [collection
     ["." list]
     ["." sequence (#+ Sequence) ("#\." comonad)]]]
   [math
    ["." random]]]
  {1
   ["." /]})

(def: (injection value)
  (Injection (/.CoFree Sequence))
  [value (sequence\map injection (sequence.repeat value))])

(def: (interpret [head tail])
  (All [a] (-> (/.CoFree Sequence a) (Sequence a)))
  (|> tail
      (sequence\map (\ (/.comonad sequence.functor) unwrap))
      [head]
      //.pending))

(def: comparison
  (Comparison (/.CoFree Sequence))
  (function (_ == left right)
    (\ (list.equivalence ==) =
       (sequence.take 100 (..interpret left))
       (sequence.take 100 (..interpret right)))))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.CoFree])
      ($_ _.and
          (_.for [/.functor]
                 ($functor.spec ..injection ..comparison (: (Functor (/.CoFree Sequence))
                                                            (/.functor sequence.functor))))
          (_.for [/.comonad]
                 ($comonad.spec ..injection ..comparison (: (CoMonad (/.CoFree Sequence))
                                                            (/.comonad sequence.functor))))
          )))