aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/project.lux
blob: 868fb769191d6ba05f129ad7cefff3dd8982affd (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(.using
 [library
  [lux (.except)
   [abstract
    [equivalence (.only Equivalence)]
    [monoid (.only Monoid)]
    ["[0]" monad (.only do)]]
   [control
    ["[0]" try (.only Try)]
    ["[0]" exception (.only exception:)]]
   [data
    ["[0]" text (.only)
     ["%" \\format (.only format)]]
    [collection
     ["[0]" dictionary (.only Dictionary)]
     ["[0]" set (.only Set)]
     ["[0]" list (.open: "[1]#[0]" mix)]]]]]
 ["[0]" //
  ["[1]" profile (.only Name Profile)]])

(def: .public file
  "project.lux")

(type: .public Project
  (Dictionary Name Profile))

(def: .public (project name profile)
  (-> Name Profile Project)
  (dictionary.of_list text.hash (list [name profile])))

(def: .public equivalence
  (Equivalence Project)
  (dictionary.equivalence //.equivalence))

(def: .public monoid
  (Monoid Project)
  (implementation
   (def: identity
     (dictionary.empty text.hash))

   (def: composite
     (dictionary.composite_with (at //.monoid composite)))))

(exception: .public (unknown_profile [name Name])
  (exception.report
   "Name" (%.text name)))

(exception: .public (circular_dependency [dependee Name
                                          dependent Name])
  (exception.report
   "Dependent" (%.text dependent)
   "Dependee" (%.text dependee)))

(def: (profile' lineage project name)
  (-> (Set Name) Project Name (Try Profile))
  (case (dictionary.value name project)
    {.#Some profile}
    (case (list.example (set.member? lineage)
                        (the //.#parents profile))
      {.#Some ouroboros}
      (exception.except ..circular_dependency [ouroboros name])
      
      {.#None}
      (do [! try.monad]
        [parents (monad.each ! (profile' (set.has name lineage) project)
                             (the //.#parents profile))]
        (in (list#mix (function (_ parent child)
                        (at //.monoid composite child parent))
                      (has //.#parents (list) profile)
                      parents))))
    
    {.#None}
    (exception.except ..unknown_profile [name])))

(def: .public profile
  (-> Project Name (Try Profile))
  (..profile' (set.empty text.hash)))