[plt-scheme] typed scheme vs. PLAI types

From: keydana at gmx.de (keydana at gmx.de)
Date: Mon Feb 15 06:34:34 EST 2010

Hi Sam, hi all,

thank you. Unfortunately it seems I still need some help using typed scheme :-(

I have the following definitions now:

(define-struct: Triple ((name : String) (typename : Symbol) (value : Any)))

(define-struct: Tuple ((triples : (Listof Triple))))

(define-struct: Relation ((heading : Heading) (body : Body)))

(define-struct: Heading ((attrs : (Listof Attribute))))

(define-struct: Attribute ((name : String) (typename : Symbol)))

(define-struct: Body ((tuples : (Listof Tuple))))

(define-datatype RelExpr
 (Rel ((rel : Relation)))
 (Union ((rel1 : RelExpr) (rel2 : RelExpr)))
 (Project ((rel : RelExpr) (attrs : Heading)))
 (Restrict ((rel : RelExpr) (prop : Prop)))
 (Join ((rel1 : RelExpr) (rel2 : RelExpr))))

(: eval-relexpr (RelExpr -> Any))
(define eval-relexpr
  (lambda (expr)
    (match expr
      ((struct Union (r1 r2)) #t)
      (else #f))))

and some sample data:

(: suppliers_1-3 Relation)
(define suppliers_1-3
    (list (make-Attribute "s#" '_string) (make-Attribute "sname" '_string) (make-Attribute "status" '_number) (make-Attribute "city" '_string)))
    (list (make-Tuple (list (make-Triple "s#" '_string "S1") (make-Triple "sname" '_string "Smith") (make-Triple "status" '_number 20) (make-Triple "city" '_string "London")))
          (make-Tuple (list (make-Triple "s#" '_string "S2") (make-Triple "sname" '_string "Jones") (make-Triple "status" '_number 10) (make-Triple "city" '_string "Paris")))
          (make-Tuple (list (make-Triple "s#" '_string "S3") (make-Triple "sname" '_string "Blake") (make-Triple "status" '_number 30) (make-Triple "city" '_string "Paris")))))))

(: suppliers_4-5 Relation)
(define suppliers_4-5
    (list (make-Attribute "s#" '_string) (make-Attribute "sname" '_string) (make-Attribute "status" '_number) (make-Attribute "city" '_string)))
    (list (make-Tuple (list (make-Triple "s#" '_string "S4") (make-Triple "sname" '_string "Clark") (make-Triple "status" '_number 20) (make-Triple "city" '_string "London")))
          (make-Tuple (list (make-Triple "s#" '_string "S5") (make-Triple "sname" '_string "Adams") (make-Triple "status" '_number 30) (make-Triple "city" '_string "Athens")))))))

Now when I try 

(eval-relexpr (make-Union suppliers_1-3 suppliers_4-5))

I get the error: typecheck: Expected RelExpr, but got Relation138 in: suppliers_1-3

I also tried annotating like this:

(ann (make-Union suppliers_1-3 suppliers_4-5) RelExpr)

but I get the same error.

When I do a simple 


I get the error:

typecheck: untyped top-level identifier suppliers_1-3 in: (#%top . suppliers_1-3)

which I also don't understand as I have the type declaration above the definition.

In general, it is not too clear to me what I have to do to use typed scheme. I understood there's no type inference, and I think I have to have a type declaration before every definition,
using the (: v t) syntax, and when I use an expression alone, I have to use the (ann v t) syntax.  But I don't know if there are any other requirements to keep in mind...

Thanks a lot for any help in this,

Am 09.02.2010 um 22:27 schrieb Sam Tobin-Hochstadt:

> On Tue, Feb 9, 2010 at 4:17 PM, keydana at gmx.de <keydana at gmx.de> wrote:
>> Hi Noel,
>> thanks a lot for the hint! I will use it then, till typed scheme will have something similar.
>> One question: how do I pattern match against the various data constructors?
> You can just use the `scheme/match' library.
> -- 
> sam th
> samth at ccs.neu.edu

Posted on the users mailing list.