[racket] Question about Typed Racket
Hi,
The following example works in Typed Racket:
(struct foo
([c : Float]
[f : (foo -> Float)]))
(define (test [f : foo]) : Float
((foo-f f) f))
(test
(foo 1.0
(lambda ([x : foo]) : Float
(match x ((foo c _) c)))))
(struct bar foo
([i : Float]))
(test
(bar 1.0
(lambda ([x : foo]) : Float
(match x
((bar c _ i) (+ c i))))
1.0))
Unfortunately, I couldn't make foo polymorphic:
(struct (R) foo
([c : R]
[f : ((foo R) -> R)]))
(define (test [f : (foo Float)]) : Float
((foo-f f) f))
(test
(foo 1.0
(lambda ([x : (foo Float)]) : Float
(match x
((foo c _) c)))))
(struct (R) bar foo
([i : Float]))
(test
(bar 1.0
(lambda ([x : (foo Float)]) : Float
(match x
((bar c _ i) (+ c i))))
1.0))
The problem is in the match in the last expression, which shows three type
errors:
Type Checker: cannot apply a function with unknown arity; function
`unsafe-struct-ref' has type Procedure which cannot be applied in: (match x
((bar c _ i) (+ c i)))
#(364 41)
Can someone tell me what I'm doing wrong here?
Thanks,
António.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150213/03084cad/attachment.html>