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
.
Asked
Active
Viewed 151 times
0

z1naOK9nu8iY5A
- 903
- 7
- 22
-
1How would you represent the data in any other language? – Phil Freeman Dec 04 '16 at 20:32
-
How do you represent heterogeneous types in a common `Entry` structure? – z1naOK9nu8iY5A Dec 08 '16 at 14:38
-
1Using a sum type perhaps. – Phil Freeman Dec 09 '16 at 02:37
1 Answers
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