define-type and type-case are provided in plai scheme, but for some reason they are not present in typed/racket. I want to implement these constructs in racket using macros.
I want to create a macro "def-user-type" following is the syntax I want to use
(def-user-type Shape
[Rectangle ((l Number) (b Number))]
[Circle ((r radius))]
[Blah (())])
And it should roughly behave as following
(define-type Shape (U Rectangle Circle Blah))
(struct: Rectangle ([l : Number] [b Number]))
(struct: Circle ([r : Number]))
(struct: Blah ())
This is what I have achieved so far. It is incorrect and the error message given by racket compiler is not helping either.
#lang typed/racket
(define-syntax define-user-type
(syntax-rules()
[(define-user-type type-name
[sub-type ((field-name type) ...)]
...)
((define-type type-name (U sub-type ...))
(struct: sub-type ([field-name : type] ...))
...)]))
Please guide me. thanks!