summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRutger Broekhoff2026-01-09 11:45:02 +0100
committerRutger Broekhoff2026-01-09 11:45:02 +0100
commit6ebee5d82d3674fe50609b308d1eaf3cdac101d1 (patch)
treed2893c3f3ab40b943e82a44da0d7eb0b9c5b49fd
parentb4bc6aecbfc4dd78409085221a8b88ee4129b171 (diff)
downloadrdcapsis-6ebee5d82d3674fe50609b308d1eaf3cdac101d1.tar.gz
rdcapsis-6ebee5d82d3674fe50609b308d1eaf3cdac101d1.zip
I have no idea what I'm doing
-rw-r--r--dune-project2
-rw-r--r--lib/ledger.ml140
-rw-r--r--rdcapsis.opam1
3 files changed, 97 insertions, 46 deletions
diff --git a/dune-project b/dune-project
index ccfa824..07d20be 100644
--- a/dune-project
+++ b/dune-project
@@ -19,7 +19,7 @@
19 (name rdcapsis) 19 (name rdcapsis)
20 (synopsis "A short synopsis") 20 (synopsis "A short synopsis")
21 (description "A longer description") 21 (description "A longer description")
22 (depends ocaml bignum bigdecimal core dmap delimited_parsing re lwd nottui nottui-lwt nottui-unix (utop :dev) (merlin :dev) (ocamlformat :dev) (odoc :doc)) 22 (depends ocaml bignum bigdecimal core dmap delimited_parsing re lwd nottui nottui-lwt nottui-unix (utop :dev) (merlin :dev) (ocaml-lsp-server :dev) (ocamlformat :dev) (odoc :doc))
23 (tags 23 (tags
24 ("add topics" "to describe" your project))) 24 ("add topics" "to describe" your project)))
25 25
diff --git a/lib/ledger.ml b/lib/ledger.ml
index 7de131f..928570f 100644
--- a/lib/ledger.ml
+++ b/lib/ledger.ml
@@ -182,62 +182,85 @@ type scalar =
182 | Rate of { in_primary_commodity : Money.Amount.t; rate : Bigdecimal.t } 182 | Rate of { in_primary_commodity : Money.Amount.t; rate : Bigdecimal.t }
183[@@deriving equal, compare, sexp_of] *) 183[@@deriving equal, compare, sexp_of] *)
184 184
185module Gh = struct 185module Account_structure0 = struct
186 (* The category of the five top-level categories *) 186 module Categories = struct
187 type global 187 (* The five top-level categories *)
188 188 type asset [@@deriving sexp_of]
189 (* The five top-level categories *) 189 type equity [@@deriving sexp_of]
190 type asset [@@deriving sexp_of] 190 type expense [@@deriving sexp_of]
191 type equity [@@deriving sexp_of] 191 type income [@@deriving sexp_of]
192 type expense [@@deriving sexp_of] 192 type liability [@@deriving sexp_of]
193 type income [@@deriving sexp_of] 193
194 type liability [@@deriving sexp_of] 194 (* Subcategories of assets *)
195 195 type bank [@@deriving sexp_of]
196 (* Subcategories of assets *) 196
197 type bank [@@deriving sexp_of] 197 (* No subcategories *)
198 198 type final [@@deriving sexp_of]
199 (* No subcategories *) 199 end
200 type final [@@deriving sexp_of]
201end
202 200
203module Account_structure0 (F : sig 201 module type Scaffold = sig
204 type 'a t [@@deriving sexp_of] 202 type 'a t [@@deriving sexp_of]
205end) = 203 end
206struct
207 type 'a f =
208 | Accounts_payable : Gh.final f F.t -> Gh.liability f
209 | Accounts_receivable : Gh.final f F.t -> Gh.asset f
210 | Bank : Gh.bank f F.t -> Gh.asset f
211 | Cash : Gh.final f F.t -> Gh.asset f
212 | Credit : Gh.final f F.t -> Gh.liability f
213 | Mutual_fund : Gh.final f F.t -> Gh.asset f
214 | Stock : Gh.final f F.t -> Gh.asset f
215 | Savings : Gh.final f F.t -> Gh.bank f
216 | Checking : Gh.final f F.t -> Gh.bank f
217 [@@deriving sexp_of]
218 204
219 type t0 = 205 module type S = sig
220 | Asset of Gh.asset f F.t 206 include Scaffold
221 | Equity of Gh.equity f F.t 207
222 | Expense of Gh.expense f F.t 208 type 'a f =
223 | Income of Gh.income f F.t 209 | Accounts_payable : Categories.final f t -> Categories.liability f
224 | Liability of Gh.liability f F.t 210 | Accounts_receivable : Categories.final f t -> Categories.asset f
225 [@@deriving sexp_of] 211 | Bank : Categories.bank f t -> Categories.asset f
212 | Cash : Categories.final f t -> Categories.asset f
213 | Credit : Categories.final f t -> Categories.liability f
214 | Mutual_fund : Categories.final f t -> Categories.asset f
215 | Stock : Categories.final f t -> Categories.asset f
216 | Savings : Categories.final f t -> Categories.bank f
217 | Checking : Categories.final f t -> Categories.bank f
218 [@@deriving sexp_of]
219
220 type t0 =
221 | Asset of Categories.asset f t
222 | Equity of Categories.equity f t
223 | Expense of Categories.expense f t
224 | Income of Categories.income f t
225 | Liability of Categories.liability f t
226 [@@deriving sexp_of]
227 end
228
229 module Make (F : Scaffold) : S with type 'a t = 'a F.t = struct
230 include F
231
232 type 'a f =
233 | Accounts_payable : Categories.final f F.t -> Categories.liability f
234 | Accounts_receivable : Categories.final f F.t -> Categories.asset f
235 | Bank : Categories.bank f F.t -> Categories.asset f
236 | Cash : Categories.final f F.t -> Categories.asset f
237 | Credit : Categories.final f F.t -> Categories.liability f
238 | Mutual_fund : Categories.final f F.t -> Categories.asset f
239 | Stock : Categories.final f F.t -> Categories.asset f
240 | Savings : Categories.final f F.t -> Categories.bank f
241 | Checking : Categories.final f F.t -> Categories.bank f
242 [@@deriving sexp_of]
243
244 type t0 =
245 | Asset of Categories.asset f F.t
246 | Equity of Categories.equity f F.t
247 | Expense of Categories.expense f F.t
248 | Income of Categories.income f F.t
249 | Liability of Categories.liability f F.t
250 [@@deriving sexp_of]
251 end
226end 252end
227 253
228module Account_type = struct 254module Account_type = struct
229 type 'a elem = Leaf | Node of 'a [@@deriving sexp_of] 255 type 'a elem = Leaf | Node of 'a [@@deriving sexp_of]
230 256
231 include Account_structure0 (struct 257 include Account_structure0.Make (struct
232 type 'a t = 'a elem [@@deriving sexp_of] 258 type 'a t = 'a elem [@@deriving sexp_of]
233 end) 259 end)
234end 260end
235 261
236module Account_structure (F : sig 262module Account_structure (F : Account_structure0.Scaffold) = struct
237 type 'a t [@@deriving sexp_of] 263 include Account_structure0.Make (F)
238end) =
239struct
240 include Account_structure0 (F)
241 264
242 module Mapper = struct 265 module Mapper = struct
243 type nonrec 'b t = { 266 type nonrec 'b t = {
@@ -301,6 +324,33 @@ struct
301 | Savings v -> f.car v 324 | Savings v -> f.car v
302 | Checking v -> f.car v 325 | Checking v -> f.car v
303 end 326 end
327
328 module Folder2 (H : Account_structure0.S) = struct
329 module type Recons = sig
330 type inner
331 type outer
332
333 module type Make = functor (G : Account_structure0.S) -> sig
334 val recons : inner G.f G.t -> outer G.f
335 end
336 end
337
338 type nonrec ('outer, 'acc) t = {
339 car : 'inner. 'inner f F.t -> ('inner H.f H.t -> 'outer H.f) -> 'acc;
340 }
341
342 let fold (type a acc) (f : (a, acc) t) : a f -> acc = function
343 | Accounts_payable v -> f.car v (fun inner -> H.Accounts_payable inner)
344 | Accounts_receivable v ->
345 f.car v (fun inner -> H.Accounts_receivable inner)
346 | Bank v -> f.car v (fun inner -> H.Bank inner)
347 | Cash v -> f.car v (fun inner -> H.Cash inner)
348 | Credit v -> f.car v (fun inner -> H.Credit inner)
349 | Mutual_fund v -> f.car v (fun inner -> H.Mutual_fund inner)
350 | Stock v -> f.car v (fun inner -> H.Stock inner)
351 | Savings v -> f.car v (fun inner -> H.Savings inner)
352 | Checking v -> f.car v (fun inner -> H.Checking inner)
353 end
304end 354end
305 355
306module Typed_account_path = struct 356module Typed_account_path = struct
diff --git a/rdcapsis.opam b/rdcapsis.opam
index 5a8adb0..bc0f8e5 100644
--- a/rdcapsis.opam
+++ b/rdcapsis.opam
@@ -24,6 +24,7 @@ depends: [
24 "nottui-unix" 24 "nottui-unix"
25 "utop" {dev} 25 "utop" {dev}
26 "merlin" {dev} 26 "merlin" {dev}
27 "ocaml-lsp-server" {dev}
27 "ocamlformat" {dev} 28 "ocamlformat" {dev}
28 "odoc" {doc} 29 "odoc" {doc}
29 "odoc" {with-doc} 30 "odoc" {with-doc}