On Sunday, February 5, 2017 at 4:06:13 AM UTC+5:30, Matthew Butterick wrote:
> On Feb 4, 2017, at 8:18 AM, Sourav Datta <soura...@gmail.com> wrote:
> 
> (require/typed "grammar1.rkt"
>              [parse (->* (Listof Token)
>                          (Any)
>                          Syntax)])
> 
> Type Checker: Type (->* (Listof Token) (Any) Syntax) could not be converted 
> to a contract: required a flat contract but generated a chaperone contract 
> in: (->* (Listof Token) (Any) Syntax)
> 
> I am not sure what this means exactly but is this because Racket does not see 
> the automatically exported function parse (or parse-tree) from a #lang brag 
> module? And, is there a way to correct this error so that I can call the 
> parse function from a TR module? 
> 
> 
> 1) That type declaration for `parse` seems both too strict (in terms of the 
> input `parse` will accept), and not quite accurate in terms of order of 
> arguments. I might do it this way:
> 
> 
> 
> (require/typed brag/support
>                [#:opaque Token token-struct?]
>                [token (->* ((U String Symbol))
>                            (Any
>                             #:line Positive-Integer
>                             #:column Natural
>                             #:position Positive-Integer
>                             #:span Natural
>                             #:skip? Boolean)
>                            Token)])
> 
> 
> (define-type Tok (U String Symbol Token Void))
> 
> 
> (require/typed "grammar1.rkt"
>                [parse (case-> ((U (Listof Tok) (-> Tok)) . -> . Any)
>                               (Any (U (Listof Tok) (-> Tok)) . -> . Any))])
> 
> 
> 
> 
> 2) If I use `Any` rather than `Syntax` as the output type, then `parse` 
> works. 

Thanks! That worked. Yes the type signatures were wrong for parse and I 
realized that after re-reading the documentation. Also, I found that instead of 
returning `Any` we could also return `(Syntaxof Any)` like this:

(define-type Input-Token (U String Symbol Token Void 'EOF))
(define-type Token-Source (U (-> Input-Token)
                             (Listof Input-Token)))
                               
                             
(require/typed "grammar1.rkt"
              [parse (case-> (-> Token-Source (Syntaxof Any))
                             (-> Any Token-Source (Syntaxof Any)))])

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to