Are there functional languages that can specify, in the typechecker, whether or not a certain computation is guaranteed to terminate? Alternatively, can you do this in just Haskell?
Regarding Haskell, in this answer the poster says that
The usual way of thinking about this is that every Haskell type is "lifted"--it contains ⊥. That is,
Bool
corresponds to{⊥, True, False}
rather than just{True, False}
. This represents the fact that Haskell programs are not guaranteed to terminate and can have exceptions.
On the other hand, this paper about Agda states that
A correct Agda program is one which passes both type-checking and termination-checking
I.e., all Agda programs will terminate, and a Bool
in Agda corresponds to exactly {True, False}
.
So for example, in Haskell you can have a value of type IO a
, which tells the typechecker that IO is needed to compute the value in question. Could you have a type Lifted a
which asserts that the computation in question may not terminate? That is, you allow non-termination, but separate it in the type system. (Obviously, as in Agda, you can only separate values into "definitely terminates" and "might not terminate") If not, are there languages that do this?
Lifted
type constructor. – Cactus