Explicit type recursion in F#

f#, recursion, type-systems

Solution

No, this is not possible. Specifically, generics in F# have the same limitation as the CLR, namely a <T> or an <'a> must have kind " * ". This same limitation is what means you cannot author "type classes" directly in F#, since e.g. "Monad m" would take a higher-kinded argument 'm' (e.g. "* -> *", where e.g. 'list' and 'option' could be instances, those each themselves being generic type constructors), but this is not allowed.

Problem

Inspired by this question: Is explicit type recursion possible in F#? ``` type 'a Mu = In of 'a Mu 'a let unIn (In x) = x ``` This code unfortunatly gives "Type parameter cannot be used as type constructor. Remarks: This construct is used in the paper Functional Programming with Overloading and Higher-Order Polymorphism, for example. Example of usage (taken from here): ``` type ('a, 'b) ListX = | Nil | Cons of 'a * 'b type 'a List = ListX Mu ```

Original source

Related problems