Pure FP: the ideal
Pure FP: Impementation
An expression is
referentially transparent
when it can always be replaced by its definition without changing the program output
copy original, modify copy
time | space | ||
---|---|---|---|
Array set element | O(1) | O(1) | ๐ |
Array copy & set element | O(n) | O(n) | ๐ |
but copying is expensive:
we can modify values
ifย theyย are no longer used
we can modify values
ifย theyย are dead
i.e. garbage collection
if "dead", modify in-place
Runtime
compile time
idea: annotate base types with a uniqueness attribute
values of a unique type can be updated destructively
unique string
non-unique string
idea: use logic expressions to encode relations
idea: use logic expressions to encode relations
UTS inference is slow, and infers large types
idea: when are two types equivalent?
well-typed if the type of \(x\) matches the type of \(f\)'s argument
idea: when are two types equivalent?
idea: when are two types equivalent?
syntactic unification is compositional
(barring the occurs check)
idea: when are two formulae equivalent?
finds the (most-general) unifier
claim: not a good fit in practice
๐
faster unification of uniqueness attributes
๐
There is a hierarchy between variables
There is a hierarchy between variables
we don't know which variable will be \(\bullet\), therefore have to keep all options available in the unifier
now we can immediately pick \(w = \bullet\)
unifies to:
"at least field \(name\) and at least field \(age\)"
A Polymorphic Type System for Extensible Records and Variants (Gaster & Jones, 1996)
rules
deriving swap
deriving swap
deriving swap
deriving swap
inferred
inferred
pure functional programs can be slow
dead values can be modified destructively
uniqueness type enable this
(and more)
UTS is slow & infers large types
Improved unification solves that
Sven-Bodo Scholz
Sjaak Smetsers
Edsko de Vries
Richard Feldman