[racket] Typed Racket: limited polymorphism?

From: Ray Racine (ray.racine at gmail.com)
Date: Tue Jun 14 20:12:32 EDT 2011

Not bounded poly but still allows the type checker to catch ill typed
attempts to make an undesirable node.

Define the node structure and constructor in a library.   Then use
appropriate  concrete constructor function(s) as needed.

To make SN nodes etc.
#lang typed/racket

(struct: (α) Node ({left : α} {right : α}))

(: create-node (All (β) (β β -> (Node β))))
(define (create-node x y)
     (Node x y))

(define-type SN (U String Number))
(define-predicate sn? SN)

(define create-sn-nodes (inst create-node SN))
(define create-str-nodes (inst create-node String))

(create-sn-nodes  "ray" 42.4) ;; ok
(create-sn-nodes 'x 4) ;; nope

(create-str-nodes "x" "y") ;; yep
(create-str-nodes 2 "z") ;; nada
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110614/2412eef7/attachment.html>

Posted on the users mailing list.