Hi everyone,

I have a strange example for you.  The following code throws an error in
typed/racket 6.7:

> (define (list1) : (Listof (Setof  Positive-Byte))
    (list (set 2) (set 3 2)))
  (apply set-union (list1))
Type Checker: Bad arguments to function in `apply':
Domain: (Setof e) (Setof e) *
Arguments: (Listof (Setof Positive-Byte)) *
in: (apply set-union (list1))

At first I thought "doh! There's a note in the docs about polymorphic
function, just use inst".  But on the other hand,

> (define list0 
    (list (set 2) (set 3 2)))
  (apply set-union list0)

Happily compiles and evaluates to the expected result.  For the record,
(inst set-union Positive-Byte) does not help.

What is weirder is that if I open a fresh repl and try:

> (define list0 : (Listof (Setof Positive-Byte)) 
    (list (set 2) (set 3 2)))
  (apply set-union list0)

It then throws the same error.

I wasn't able to get the same error with other polymorphic functions as
much as I tried. It turns out this is limited to set-union and
set-subtract.  the type signatures of this functions are:
(-> (Setof e) (Setof e) * (Setof e))

Therein lies our problem.  we need to curry set-union, et al, to get rid
of that leading argument!  But to curry we run into polymorphic type
problems.  so we do:

> (apply (curry (inst set-union Positive-Byte) (ann (set) (Setof 
> Positive-Byte))) (list1))

That's a bit of a mouthful, but racket is as happy as a clam.  Might I
hope for a cleaner way to write this in a later version?
Somewhat related, I have one parting question: Out of the two:

> (define list0 
    (list (set 2) (set 3 2)))
  (apply set-union list0)

> (define list2 : (Listof (Setof Positive-Byte)) 
    (list (set 2) (set 3 2)))
  (apply set-union list2)

Why does the former work and the latter fail ?

Thanks,

Matthew Eric

-- 
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.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to