Module fungi_lang::examples
source · Expand description
Examples of data structures and algorithms in Fungi.
Basics
These (very small) examples demonstrate basic concepts from Fungi’s type and effect system:
basic_read_effects
— read effects track the reference cells and thunks that a Fungi program observes and forces.basic_write_effects
— write effects track the reference cells and thunks that a Fungi program allocates.basic_write_scope
— write scopes distinctly qualify written names for different dynamic calling contexts.basic_subtyping
— subtyping permits structures with fewer names to be used in contexts that expect more names.basic_existentials
— existential types permit packing names and named structures into types that approximate them.
FP Basics in Fungi
Basic patterns from functional programming (FP), in the “pure” fragment of Fungi. The pure effect (written 0
, for short) means that a computation lacks read and write effects.
op_nat
— Simple primitives for optional natural numberspure_list_nat
— Simple primitives for lists of natural numbers
Lists
Linked lists whose cons cells contain names, and whose tail pointers are (named) reference cells.
list_nat
— Primitives for lists of natural numberslist_nat_dedup
— Deduplicate input list elements; uses a hash trie
Tries
Hash tries that represent functional sets, with named elements.
trie_nat
— Primitives for tries of natural numbers
Sequences
Sequences of natural numbers, represented as probabilistically-balanced binary trees (level trees), with names and reference cells:
seq_max
— finds the maximum element in a sequence.seq_filter
— filters a sequence of elements, producing a new (smaller) sequence.
Modules
Primitive utilities:
Optional natural numbers
Lists of natural numbers, without names, and with pure operations.
Filter a sequence of elements, producing a new (smaller) sequence
Find the maximum element in a sequence