0 | ||| Modular records based on `All`
6 | %hide Data.List.Quantifiers.Any.Any
7 | %hide Data.List.Quantifiers.Any.any
13 | ||| A type with a string-label for it. Used in `Record`
14 | |||
15 | ||| ```idris example
16 | ||| IntLabel : KeyVal
17 | ||| IntLabel = "int" :-: Int
18 | ||| ```
25 | ||| The value-constructor for `KeyVal`, essentially a pair of a label
26 | ||| and a value that match the specification given by `KeyVal`
27 | |||
28 | ||| ```idris example
29 | ||| IntLabel : KeyVal
30 | ||| IntLabel = "int" :-: Int
31 | |||
32 | ||| intValue : LabelledValue IntLabel
33 | ||| intValue = "int" :- 3
34 | ||| ```
38 | ||| The label matching the `KeyVal` spec, erased for performance reasons
40 | ||| A proof that the label given matches the label in the specification
42 | ||| A runtime value of the type given by the specification
45 | ||| Records are a list of of labelled values, their fields are given by a list of KeyVal
46 | ||| Each element in the list describes a key
47 | |||
48 | ||| ```idris example
49 | ||| Spec : List KeyVal
50 | ||| Spec = [ "username" :-: String, "amount" :-: Double ]
51 | |||
52 | ||| recordValue : Record Spec
53 | ||| recordValue = [ "username" :- "Alice", "amount" :- 3.14 ]
54 | ||| ```
59 | ||| Build a record from it's element values ignoring the labels
60 | |||
61 | ||| ```idris example
62 | ||| Spec : List KeyVal
63 | ||| Spec = [ "username" :-: String, "amount" :-: Double ]
64 | |||
65 | ||| recordValue : Record Spec
66 | ||| recordValue = fromElems [ "Alice", 3.14 ]
67 | ||| ```
68 | export
73 | ||| Obtain the tail of a list of predicates
74 | export
78 | ||| A procedue to find the type at the given index
85 | ||| A procedure to find the index and type of a given label
93 | -- Convert a `NameInRange` proof to a `FindIndex` proof
94 | 0
100 | IndexInRange {fields = ((label :-: type) :: xs)} {ty} prf | False with (NameInRange key xs) proof p
106 | ||| Add a label and a value to a record
107 | export
114 | ||| Obtain the value from a record at given index
115 | ||| @ n The index at which we extract the value.
116 | ||| @ out The type of the value at the index.
117 | ||| @ inRange A proof that the field is in the record at the appropriate index with the appropriate type.
118 | export
125 | ||| Obtain the value from a record given its label.
126 | ||| @ field The field for which we extract the value.
127 | ||| @ n The index corresponding to the field given.
128 | ||| @ out The type of the value at the given field.
129 | ||| @ inRange A proof that the field is in the record at the appropriate index with the appropriate type.
130 | export
136 | ||| Obtain the value from a record given its label and type.
137 | ||| @ field The field for which we extract the value.
138 | ||| @ out The type of the value at the given field.
139 | ||| @ n The index corresponding to the field given.
140 | ||| @ inRange A proof that the field is in the record at the appropriate index with the appropriate type.
141 | export
145 | out
148 | ||| Remove a value from the list, used in the type of `removeAt`
158 | ||| Remove the value at the given index.
159 | ||| @ n The index we are removing.
160 | ||| @ inRange A proof that the index is in range of the record spec.
161 | export
171 | ||| Update the value at the given index.
172 | ||| @ n The index we are removing.
173 | ||| @ inRange A proof that the index is in range of the record spec.
174 | ||| @ f The update function.
175 | export
186 | ||| Update the value with the given label.
187 | ||| @ field The label of the value we are updating.
188 | ||| @ inRange A proof that the label is in the record at the appropriate index with the appropriate type.
189 | ||| @ f The update function.
190 | export
198 | ||| Override the value found at the given index.
199 | ||| @ n The index we are removing.
200 | ||| @ inRange A proof that the index is in range of the record spec.
201 | ||| @ newVal The value that will replace the existing one.
202 | export
208 | ||| Override the value found at the given label.
209 | ||| @ label The label of the value we are overriding.
210 | ||| @ inRange A proof that the label is in the record at the appropriate index with the appropriate type.
211 | ||| @ newVal The value that will replace the existing one.
212 | export