7

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?

Benjamin Hodgson
  • 42,952
  • 15
  • 108
  • 157
MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102
  • 1
    @HarryDeveloper1212 I think this is a good question. I've made some edits in order to (I hope) clarify what I understood the question to mean. If you're unhappy with my changes, feel free to [edit your question](http://stackoverflow.com/posts/34617662/edit) again to put it back. – Benjamin Hodgson Jan 06 '16 at 01:12

1 Answers1

20

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.

Reid Barton
  • 14,951
  • 3
  • 39
  • 49