I've been messing around with recursive types, and I'm currently trying to create the Y combinator at the type level.
Essentially, I would like a type Y<f> = ...
where f
is itself a type.
I've tried to adapt this lisp code:
(define (Y f)
((lambda (x) (x x))
(lambda (x) (f (x x)))))
I can simply create a type for (lambda (x) (x x))
with:
type self_call<X> = X<X>
What I'm struggling with is finding a way to express (lambda (x) (f (x x))))
. I need to pass f
into some sort of type that creates this, but I'm not sure how to create a type that returns a custom type, or if it's even possible. I'm starting to feel like I've gone the wrong way with this.
Is it possible to create such a Y<f>
type, and if so, how?