Discussion:
[racket] Question about Typed Racket
Antonio Menezes Leitao
2015-02-13 01:21:53 UTC
Permalink
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.
Sam Tobin-Hochstadt
2015-02-13 01:31:04 UTC
Permalink
I don't think you're doing anything wrong, and I expect that this case
[1] needs a bit of generalization to handle polymorphic structs.

[1] https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-hetero.rkt#L82-L83

Sam

On Thu, Feb 12, 2015 at 8:21 PM, Antonio Menezes Leitao
Post by Antonio Menezes Leitao
Hi,
(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))
(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
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.
____________________
http://lists.racket-lang.org/users
____________________
Racket Users list:
http:/
Antonio Menezes Leitao
2015-02-13 12:06:49 UTC
Permalink
BTW, are there any plans for supporting #:constructor-name in Typed Racket
struct?

Best,
António.

Loading...