❮❮❮
Bonsai
❮❮❮
❯❯❯
Using Gurobi operators from F#
❯❯❯
Algebraic_datastructures
Thoughts about algebraic datastructures.
Reading time: 2 min.
Thoughts about algebraic datastructures, as found in ML style languages (SML, Ocaml, F#, Elm, Haskell, Scala, …).
Atomic types
- They are atomic and thus not interesting.
- Important later are
- the type
Natof natural numbers (starting at 0). - the type
Fin n, forn : Nat, which describes the values[1, ..., n]Fin 0has no values, i.e. describes the values in[].
- the type
Core composite types
Arrays
- Abstract:
Array ais dollection ofn : Natelements of the same typea.- Indices are from
Fin nand are1-based.
- Indices are from
- Concrete: Constant time access.
- Could be simulated by a hidden tree, but with different runtime cost.
- Hence assumed as builtin.
Tuples
- Abstract:
Tuple [a_1, ..., a_n]hasn : Natmany elements of fixed arbitrary typesa_1, ..., a_n.- Access is via pattern matching or special
Fin naccessors. - The one-tuple exists and boxes its content.
- The empty tuple is its own type.
- Access is via pattern matching or special
Finite DUs
- Abstract:
FDU [a_1, ..., a_n]describesn : Natmany alternatives of fixed arbitrary typesa_1, ..., a_n.- Access is via pattern matching. The DU tag is from
Fin n. - The empty
FDU []is possible.
- Access is via pattern matching. The DU tag is from
Duality
- There is a duality between
Tuple [a_1, ..., a_n]andFDU [a_1, ..., a_n], as the share the same types and label setFin n.
Core algebraic types
Label
- Let
Labelbe an infinite set of distinct symbols used for labelling.