type liability_type =
  | Loan
  | Mortgage
  | Credit_card
  | Other

let liability_type_to_string (lt : liability_type) : LString.t =
  match lt with
  | Loan -> {l|Loan|l}
  | Mortgage -> {l|Mortgage|l}
  | Credit_card -> {l|Credit Card|l}
  | Other -> {l|Other|l}

type liability = {
  amount : real;
}

let create_liability (amount : real) : liability option =
  if amount >=. 0.0 then
    Some { amount = amount }
  else
    None

let liability_equal (l1 : liability) (l2 : liability) : bool =
  l1.amount = l2.amount

let liability_to_dict (l : liability) : (LString.t * real) list =
  [({l|amount|l}, l.amount)]

let liability_from_dict (data : (LString.t * real) list) : liability option =
  match List.assoc {l|amount|l} data with
  | Some amount -> create_liability amount
  | None -> None

let main () : unit =
  let liability_opt = create_liability 5000.0 in
  match liability_opt with
  | Some liability ->
    let liability2_opt = create_liability 5000.0 in
    (match liability2_opt with
     | Some liability2 ->
       let are_equal = liability_equal liability liability2 in
       let liability_dict = liability_to_dict liability in
       let liability_from_dict_opt = liability_from_dict liability_dict in
       ()
     | None -> ())
  | None -> ()
