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
_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Reply via email to