Greetings.
Consider the following:
#lang typed/racket
;#lang typed/racket/no-check ; <-- this works as expected
(: func (case->
([#:as (U Integer False)] -> Any)
(Integer [#:as (U Integer False)] -> Any)))
(define (func (arg1 #f) #:as (opt-arg #f))
(cond (arg1 (or arg1 #f)); <-- removing this expression means
things work as expected
(else
(eprintf "func: opt-arg=~s, so (or ~s #f) -> ~s~%"
opt-arg opt-arg (or opt-arg #f))
(or opt-arg #f))))
(func #:as 1)
(func 1)
When run...
% racket -v
Welcome to Racket v6.3.
% racket test.rkt
func: opt-arg=1, so (or 1 #f) -> #f
#f
1
%
That is, in the first case (or 1 #f) appears to evaluate to #f, not 1 as
expected. Very much not as expected.
If I replace the definition with
(define (func (arg1 #f) #:as (opt-arg : (U Integer False) #f))
...)
then this works as expected. That is, TR appears to be typing opt-arg,
within the function, as False, and rewriting the (or opt-arg #f)
accordingly. It's not doing the same with the (arg1 (or arg1 #f))
clause.
Given that I've typed the func function before defining it, and have
typed the #:as argument as (U Integer False), I would not expect to have
to repeat myself in the function definition.
Related, perhaps: If I declare the type of 'func' as follows:
(: func (case->
([#:as Integer] -> Any)
(Integer [#:as Integer] -> Any)))
Then the default opt-arg value does not match the function type. This
does not produce any error or warning, and this suggests to me that this
declaration is not being examined when the function is defined. I would
have expected this to be caught as a type error.
That said, the following program 'works'
#lang typed/racket
(: f ([#:o Integer] -> Any))
(define (f #:o (opt-arg #f))
(or opt-arg #f))
(f #:o 1) ; --> 1
So it's not just a matter of 'type of optional arguments is too narrow'.
Also, this program has the same glaring type error in it.
----
What _may_ be a related issue is that, if I try the program at the top
in DrRacket with the 'Debug' button, I get an error message:
Welcome to DrRacket, version 6.3 [3m].
Language: typed/racket [custom]; memory limit: 128 MB.
exception raised by error display handler: normalize-path: element
within the input path is not a directory or does not exist
element: /home/ryan; original exception raised:
expr-syntax-object-iterator: unknown expr: (quote-syntax (:-internal
func (case-> ((#:as Integer) -> Any) (Bytes (#:as Integer) -> Any)))
#:local)
But this may be a separate issue, because if I put the smaller program,
above, into DrRacket, and press Debug, I get
../../Data/LocalApplications/Racket/6.3/share/pkgs/drracket/gui-debugger/annotator.rkt:227:6:
expr-syntax-object-iterator: unknown expr: (quote-syntax (:-internal f
((#:o Integer) -> Any)) #:local)
I don't know if this is related, but I wouldn't have expected to see a
/home/ryan above. Additionally, doing
find /Data/LocalApplications/Racket/6.3 -type f | xargs grep
/home/ryan
...I get _lots_ of matches. Is there a possible build glitch here?
----
I'm on OS X, 10.10.5
The same thing happens as far back as Racket 5.3.6, which is the
earliest I have to hand.
Best wishes,
Norman
--
Norman Gray : https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK
--
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.