I know that the set of Haskell functions is only a subset of all mathematical functions, because it is a programming language, so all of its functions must be computable. But is it true that all Haskell functions (and pure functions in general) are continuous, from a mathematical point of view?
Pure functions are deterministic and have no side effects. Deterministic: for same input x , output y should always be the same. Side effect: use of external dependency or variable mutations.
In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams), and.
Theorem: There are no discontinuous functions. Theorem (classically equivalent form): All functions are continuous. When constructive mathematicians says that “all functions are continuous” they have something even better in mind. They are telling you that all functions are computably continuous.
Persistency is required for functional programming; without it, the same computation could return different results. Functional programming may use persistent non-purely functional data structures, while those data structures may not be used in purely functional programs.
Computable functions are continuous in the sense of Scott continuity, mentioned in the second paragraph of the Wikipedia page you linked to.
An example of a function which is not continuous is (pseudo-Haskell)
isInfinite :: [a] -> Bool
isInfinite xs
| {- xs is an infinite list x0 : x1 : x2 : ... -} = True
| {- xs is a finite list x0 : x1 : x2 : ... : xn : [] -} = False
| {- xs is a list with diverging spine
x0 : x1 : x2 : ... : xn : _|_ -} = _|_
It fails to be continuous because
() : () : () : ...
is the supremum of the sequence
_|_
() : _|_
() : () : _|_
...
but
True = isInfinite (() : () : () : ...)
is not the supremum of the sequence
_|_ = isInfinite (_|_)
_|_ = isInfinite (() : _|_)
_|_ = isInfinite (() : () : _|_)
...
Computable functions are continuous, essentially because in a finite amount of time a function can only inspect a finite amount of its input. So if a computable function returns, say, True
on a particular input, it must return True
on every input in the set of inputs which agree with the original input on a certain finite collection of observations. Any increasing sequence which converges to the original input will eventually land and stay inside this set, so the sequence of values of the function on this increasing sequence will converge to True
.
A continuous function is not necessarily computable. For example any order-preserving (i.e. f _|_ = _|_
, or f
is constant) function Integer -> Bool
is continuous, since Integer
is a flat domain. But of course only countably many of them are computable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With