[plt-scheme] typed scheme problem: "Expected Attribute, but got Attribute"

From: keydana at gmx.de (keydana at gmx.de)
Date: Sun Apr 25 12:31:52 EDT 2010

Ah you're right, I'm sorry. Here is a piece now which works (apart from the error it's about):

#lang typed/scheme
(require scheme/match)
(require (planet dherman/types:2))

(define-datatype Value
  (S ((s : String)))
  (N ((n : Real))))

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

(define-datatype Operator
  (Greater #:constant greater)
  (GreaterEql #:constant greatereql)
  (Less #:constant less)
  (LessEql #:constant lesseql)
  (Eql #:constant eql)
  (NotEql #:constant noteql))

(define-type Operand (U Attribute Value))

(define-datatype Predicate
 (Is ((op : Operator) (rand1 : Operand) (rand2 : Operand)))
 (Not ((p : Predicate)))
 (And ((p1 : Predicate) (p2 : Predicate)))
 (Or ((p1 : Predicate) (p2 : Predicate))))

(define p (make-Is eql (make-Attribute "name" 'type) (make-N 3.6))) 
(display (match p
           ((struct Is (op r1 r2)) (cond ((Attribute? r1) (Attribute-typename r1))
                                         (else #f)))))

Ciao,
Sigrid



Am 25.04.2010 um 14:01 schrieb Sam Tobin-Hochstadt:

> On Sun, Apr 25, 2010 at 2:06 AM, keydana at gmx.de <keydana at gmx.de> wrote:
>> 
>> I'm stuck with a problem during type matching in typed scheme which I don't
>> know how to get along with. Somehow I suspect it might be related to nesting
>> type definitions in the standard type scheme (define-struct: and
>> define-type)
>> and the planet dherman/types:2 package (define-datatype) way, like this:
> 
> There seems to be some missing code in your example.  What is `eql'
> and what is `Operator'?  Neither of them are defined.
> -- 
> sam th
> samth at ccs.neu.edu



Posted on the users mailing list.