Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
Created May 12, 2021 15:03
Show Gist options
  • Save ebresafegaga/0b66ce802ed63d9909f7ff8465cc414d to your computer and use it in GitHub Desktop.
Save ebresafegaga/0b66ce802ed63d9909f7ff8465cc414d to your computer and use it in GitHub Desktop.
Recursive types in Typed Racket
#lang typed/racket
(define-type Hungry (Rec X (Natural -> X)))
(: f Hungry)
(define (f _) f)
(define-type (Stream X) (Rec A (Void -> (List Natural A))))
; U-combinator (self application)
(: U (∀ [T] (Rec X (X -> T)) -> T))
(define (U f) (f f))
; Y-combinator
(: fix (∀ [T] (T -> T) -> T))
(define (fix f)
(U (λ ([x : (Rec A (A -> T))]) (f (x x)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment