Given is a Javascript function like
const isNull = x => x === null ? [] : [isNull];
Such a function might be nonsense, which is not the question, though.
When I tried to express a Haskell-like type annotation, I failed. Likewise with attempting to implement a similar function in Haskell:
let isZero = \n -> if n == 0 then [] else [isZero] -- doesn't compile
Is there a term for this kind of functions that aren't recursive themselves, but recursive in their type? Can such functions be expressed only in dynamically typed languages?
Sorry if this is obvious - my Haskell knowledge (including strict type systems) is rather superficial.
You need to define an explicit recursive type for that.
The price to pay is the wrapping/unwrapping of the
Tconstructor, but it is feasible.If you want to emulate a Javascript-like untyped world (AKA unityped, or dynamically typed), you can even use
(beware of a known bug)
In principle, every Javascript value can be represented by the above huge sum type. For example, application becomes something like
Note how static type checks are turned into dynamic checks, in this way. Similarly, static type errors are turned into runtime errors.