diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ledger.ml | 111 |
1 files changed, 70 insertions, 41 deletions
diff --git a/lib/ledger.ml b/lib/ledger.ml index 928570f..7bb824c 100644 --- a/lib/ledger.ml +++ b/lib/ledger.ml | |||
| @@ -202,33 +202,7 @@ module Account_structure0 = struct | |||
| 202 | type 'a t [@@deriving sexp_of] | 202 | type 'a t [@@deriving sexp_of] |
| 203 | end | 203 | end |
| 204 | 204 | ||
| 205 | module type S = sig | 205 | module Make (F : Scaffold) = struct |
| 206 | include Scaffold | ||
| 207 | |||
| 208 | type 'a f = | ||
| 209 | | Accounts_payable : Categories.final f t -> Categories.liability f | ||
| 210 | | Accounts_receivable : Categories.final f t -> Categories.asset f | ||
| 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 = | 206 | type 'a f = |
| 233 | | Accounts_payable : Categories.final f F.t -> Categories.liability f | 207 | | Accounts_payable : Categories.final f F.t -> Categories.liability f |
| 234 | | Accounts_receivable : Categories.final f F.t -> Categories.asset f | 208 | | Accounts_receivable : Categories.final f F.t -> Categories.asset f |
| @@ -249,7 +223,32 @@ module Account_structure0 = struct | |||
| 249 | | Liability of Categories.liability f F.t | 223 | | Liability of Categories.liability f F.t |
| 250 | [@@deriving sexp_of] | 224 | [@@deriving sexp_of] |
| 251 | end | 225 | end |
| 252 | end | 226 | |
| 227 | module Gen_f_cons = struct | ||
| 228 | module type S = sig | ||
| 229 | type inner | ||
| 230 | type outer | ||
| 231 | |||
| 232 | module Specialize : functor | ||
| 233 | (F : Scaffold) | ||
| 234 | (G : module type of Make (F)) | ||
| 235 | -> sig | ||
| 236 | val cons : inner G.f F.t -> outer G.f | ||
| 237 | end | ||
| 238 | end | ||
| 239 | |||
| 240 | module Accounts_payable : | ||
| 241 | S with type outer = Categories.liability and type inner = Categories.final = | ||
| 242 | struct | ||
| 243 | type outer = Categories.liability | ||
| 244 | type inner = Categories.final | ||
| 245 | |||
| 246 | module Specialize (F : Scaffold) (G : module type of Make (F)) = struct | ||
| 247 | let cons inner = G.Accounts_payable inner | ||
| 248 | end | ||
| 249 | end | ||
| 250 | end | ||
| 251 | end | ||
| 253 | 252 | ||
| 254 | module Account_type = struct | 253 | module Account_type = struct |
| 255 | type 'a elem = Leaf | Node of 'a [@@deriving sexp_of] | 254 | type 'a elem = Leaf | Node of 'a [@@deriving sexp_of] |
| @@ -325,22 +324,52 @@ module Account_structure (F : Account_structure0.Scaffold) = struct | |||
| 325 | | Checking v -> f.car v | 324 | | Checking v -> f.car v |
| 326 | end | 325 | end |
| 327 | 326 | ||
| 328 | module Folder2 (H : Account_structure0.S) = struct | 327 | module Folder2 = 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 = { | 328 | type nonrec ('outer, 'acc) t = { |
| 339 | car : 'inner. 'inner f F.t -> ('inner H.f H.t -> 'outer H.f) -> 'acc; | 329 | car : |
| 330 | 'inner. | ||
| 331 | 'inner f F.t -> | ||
| 332 | (module Account_structure0.Gen_f_cons.S | ||
| 333 | with type inner = 'inner | ||
| 334 | and type outer = 'outer) -> | ||
| 335 | 'acc; | ||
| 340 | } | 336 | } |
| 341 | 337 | ||
| 342 | let fold (type a acc) (f : (a, acc) t) : a f -> acc = function | 338 | 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) | 339 | | Accounts_payable v -> |
| 340 | f.car v (module Account_structure0.Gen_f_cons.Accounts_payable) | ||
| 341 | | _ -> failwith "kaas" | ||
| 342 | (* | ||
| 343 | | Accounts_receivable v -> | ||
| 344 | f.car v (fun inner -> H.Accounts_receivable inner) | ||
| 345 | | Bank v -> f.car v (fun inner -> H.Bank inner) | ||
| 346 | | Cash v -> f.car v (fun inner -> H.Cash inner) | ||
| 347 | | Credit v -> f.car v (fun inner -> H.Credit inner) | ||
| 348 | | Mutual_fund v -> f.car v (fun inner -> H.Mutual_fund inner) | ||
| 349 | | Stock v -> f.car v (fun inner -> H.Stock inner) | ||
| 350 | | Savings v -> f.car v (fun inner -> H.Savings inner) | ||
| 351 | | Checking v -> f.car v (fun inner -> H.Checking inner) *) | ||
| 352 | end | ||
| 353 | |||
| 354 | module Folder3 (Acc : sig | ||
| 355 | type 'a t | ||
| 356 | end) = | ||
| 357 | struct | ||
| 358 | type nonrec 'outer t = { | ||
| 359 | car : | ||
| 360 | 'inner. | ||
| 361 | 'inner f F.t -> | ||
| 362 | (module Account_structure0.Gen_f_cons.S | ||
| 363 | with type inner = 'inner | ||
| 364 | and type outer = 'outer) -> | ||
| 365 | 'outer Acc.t; | ||
| 366 | } | ||
| 367 | |||
| 368 | let fold (type a) (f : a t) : a f -> a Acc.t = function | ||
| 369 | | Accounts_payable v -> | ||
| 370 | f.car v (module Account_structure0.Gen_f_cons.Accounts_payable) | ||
| 371 | | _ -> failwith "kaas" | ||
| 372 | (* | ||
| 344 | | Accounts_receivable v -> | 373 | | Accounts_receivable v -> |
| 345 | f.car v (fun inner -> H.Accounts_receivable inner) | 374 | f.car v (fun inner -> H.Accounts_receivable inner) |
| 346 | | Bank v -> f.car v (fun inner -> H.Bank inner) | 375 | | Bank v -> f.car v (fun inner -> H.Bank inner) |
| @@ -349,7 +378,7 @@ module Account_structure (F : Account_structure0.Scaffold) = struct | |||
| 349 | | Mutual_fund v -> f.car v (fun inner -> H.Mutual_fund inner) | 378 | | Mutual_fund v -> f.car v (fun inner -> H.Mutual_fund inner) |
| 350 | | Stock v -> f.car v (fun inner -> H.Stock inner) | 379 | | Stock v -> f.car v (fun inner -> H.Stock inner) |
| 351 | | Savings v -> f.car v (fun inner -> H.Savings inner) | 380 | | Savings v -> f.car v (fun inner -> H.Savings inner) |
| 352 | | Checking v -> f.car v (fun inner -> H.Checking inner) | 381 | | Checking v -> f.car v (fun inner -> H.Checking inner) *) |
| 353 | end | 382 | end |
| 354 | end | 383 | end |
| 355 | 384 | ||