<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi all,<div><br></div><div>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)</div><div>and the planet dherman/types:2 package (define-datatype) way, like this:</div><div><br></div><div><div>#lang typed/scheme</div><div>(require scheme/match)</div><div>(require (planet dherman/types:2))</div><div><br></div></div><div><div>(define-struct: Attribute ((name : String) (typename : Symbol)) #:mutable)</div><div><br></div><div><div>(define-datatype Value</div><div> (S ((s : String)))</div><div> (N ((n : Real))))</div></div><div><br></div><div><div>(define-type Operand (U Attribute Value))</div><div><br></div><div>(define-datatype Predicate</div><div> (Is ((op : Operator) (rand1 : Operand) (rand2 : Operand)))</div><div> (Not ((p : Predicate)))</div><div> (And ((p1 : Predicate) (p2 : Predicate)))</div><div> (Or ((p1 : Predicate) (p2 : Predicate))))</div><div><br></div><div>Now when I try something like this:</div><div><br></div><div><div>(define p (make-Is eql (make-Attribute "name" 'type) (make-N 3.6)))</div><div>(display (match p</div><div> ((struct Is (op r1 r2)) (cond ((Attribute? r1) (Attribute-typename r1))</div><div> (else #f)))))</div><div><br></div><div>I get the error</div><div><br></div><div>Type Checker: Expected Attribute, but got Attribute in: r1</div><div><br></div><div><br></div><div>I have no idea what to do with this - alone, both the use of match for types defined with define-datatype works fine, and the use of cond to match types defined as unions is like in the typed scheme documentation 2.1 chapter.</div><div>Could someone help?</div><div><br></div><div>Also in general, my mixed usage of both makes the matching code itself look <span class="Apple-style-span" style="border-collapse: collapse; font-family: 'Lucida Grande'; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">awkward when nesting the different ways of definition. In the above example, I test for Attribute with Attribute?, but when I need to test for Value I have to</span></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">write</span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">(or (N? rand1) (S? rand1)</span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">- or at least that's the only way I found, so I have "different granularities" somehow. Would someone perhaps know a better way of handling this?</span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Many thanks in advance for any help,</span></font></div><div><font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="border-collapse: collapse; font-size: 11px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Sigrid</span></font></div></div></div></div></body></html>