0

Given that my Purescript program contains different types representing items that can be exchanged, for example Vegetable, Milk, Meat etc., what is the best way to represent a ledger data-structure that tracks the exchanges between participants? To simplify we can represent participants as type Participant = Int.

z1naOK9nu8iY5A
  • 903
  • 7
  • 22

1 Answers1

0

You can use purescript-variant for open sums.

type Ledger products = Array (Entry products)

type Entry products =
  { date ∷ DateTime
  , product ∷ Variant products
  , unitPrice ∷ Int
  , quantity ∷ Int
  }

A Ledger type can then be instantiated for a particular set of products, such as Ledger (milk ∷ Milk, vegetable ∷ Vegetable, meat ∷ Meat).

erisco
  • 14,154
  • 2
  • 40
  • 45