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

From: keydana at gmx.de (keydana at gmx.de)
Date: Tue Apr 27 13:20:14 EDT 2010

Hi all,

I'm afraid it's horribly impolite to be pressing like this, but I'm really totally stuck with this type matching problem, in fact I cannot go on without at all, type matching being fundamental everywhere in the code...
I don't know if I'm simply overlooking something here or if something more complicated is going on (possibly related to the mixing of the different ways of defining types?).

I'd be grateful for any hint what I might do/try here :-;

Here again (because of the changed subject) is the code:

#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




---------------------------------------------------------------------------------------------------------------------------



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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100427/3fbad2af/attachment.html>

Posted on the users mailing list.