[racket] Typed Racket - Parameterized Structures

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Mar 14 08:28:36 EDT 2012

2012/3/14 Ray Racine <ray.racine at gmail.com>:
> I could use an assist on getting the following to type check.

The program below works.  I made two changes.

1. You added `All' in the type parameter list for `struct:'.  You
don't need that there, and instead it was adding a third type
parameter to `Cvt'.

2. There's some problem with inference and struct accessors, which
makes the use of `ann' below required.  I've filed that as bug 12631,
and hope to fix it soon.

#lang typed/racket/base

(struct: (T0 T1) Cvt ([cvt : (T0 -> T1)]))

(: cvt-apply (All (T0 T1) (T0 (Cvt T0 T1) -> T1)))
(define (cvt-apply value cvt)
  ((ann (Cvt-cvt cvt) (T0 -> T1)) value))

(: ItoS-Convert (Cvt Integer String))
(define ItoS-Convert
  (Cvt (λ: ((x : Integer)) "Hello")))

(: ItoS (Integer -> String))
(define (ItoS int)
  (cvt-apply int ItoS-Convert))

sam th
samth at ccs.neu.edu

Posted on the users mailing list.