Re: [racket-users] Inference for polymorphic functions not supported?

2020-05-19 Thread Hendrik Boom
On Mon, May 18, 2020 at 04:51:26PM -0400, Sam Tobin-Hochstadt wrote:
> The systematic way to do it is to use `inst`.
> 
> Here's the first example:
> 
> (define hash-list : (Listof (Pair Symbol Natural)) (list))
> ((inst sort (Pair Symbol Natural) String) hash-list string ((p : (Pair Symbol Natural))) (symbol->string (car p))) #:cache-keys?
> #t)
> 
> This program works already, but I wasn't sure what the `y` binding was
> doing in your second example:
> 
> (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol
> Natural) (in-list hash-list))
>  (k : Symbol (in-value (car p)))
>  (v : Natural (in-value (cdr p)))
>  #:when (not (= v 1))
>  )
>   (cons k v))

I got this second example to work, but it's still a black art to me.

 (printf "~s~%"
`(define pname-map (hasheqv
 ,@(for*/list : (Listof (List Symbol Natural))
 ((p  : (Pair Symbol Natural)(in-list 
(hash->sorted-list pname-map)))
  (k : Symbol (in-value (car p)))
  (v : Natural (in-value (cdr p)))
  #:when (not (= v 1))
  )
 (list k v) ; TODO: I changed this; 
original used a temporary variable 'y'.
 

I really had to get rid of the y variable.  Even providing an explicit type for 
that 
variable did not work.

It kept complaining about the overloaded function 'cons'.

Presumably I'd have to use inst on the 'cons' function to clear this up 
comprehensibly, 
but 'cons' does not appear explicitly in the code at all.

It's probably embedded in the code generated by quasiquote.  The 'inst' tril 
doesn't 
work very well on code generated by a macro when the macro itself doesn't 
generate 
'inst's.

I do not understand how eliminating the temporary variably 'y' made it all work.

-- hendrik

> 
> Sam
> 
> On Mon, May 18, 2020 at 4:33 PM Hendrik Boom  wrote:
> >
> > I keep getting the messages like
> >
> > Type Checker: Inference for polymorphic keyword functions not supported in: 
> > (sort hash-list string > (symbol->string (car p))) #:cache-keys? #t)
> >
> > or
> >
> > Type Checker: Polymorphic function `cons' could not be applied to arguments:
> > Types: a (Listof a) -> (Listof a)
> >a b -> (Pairof a b)
> > Arguments: (U Exact-Nonnegative-Integer Symbol) (Listof (Pairof Symbol 
> > Nonnegative-Integer))
> > Expected result: (Listof (Pairof Symbol Nonnegative-Integer))
> >  in: (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol 
> > Natural) (in-list (hash->sorted-list pname-map))) (k : Symbol (in-value 
> > (car p))) (v : Natural (in-value (cdr p))) #:when (not (= v 1)) (y (list k 
> > v))) y)
> >
> > Is there some systematic way to code this explicitly so it
> > doesn't have to try guesswork? (hich it refuses to do)
> >
> > And is it really unable to figure out that an
> > Exact-Nonnegative-Integer is a Nonnegative-Integer?
> >
> > -- hendrik
> >
> > --
> > 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.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/racket-users/20200518203342.4vcvrsrvkmld4tmh%40topoi.pooq.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200519105800.gwojekkthcexivbz%40topoi.pooq.com.


Re: [racket-users] Inference for polymorphic functions not supported?

2020-05-18 Thread Hendrik Boom
On Mon, May 18, 2020 at 04:51:26PM -0400, Sam Tobin-Hochstadt wrote:
> The systematic way to do it is to use `inst`.
> 
> Here's the first example:
> 
> (define hash-list : (Listof (Pair Symbol Natural)) (list))
> ((inst sort (Pair Symbol Natural) String) hash-list string ((p : (Pair Symbol Natural))) (symbol->string (car p))) #:cache-keys?
> #t)
> 
> This program works already, but I wasn't sure what the `y` binding was
> doing in your second example:

I don't either.  It was originally someone else's program, which I'm coverting 
to typed 
Racket in order to understand it better.

-- hendrik

> 
> (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol
> Natural) (in-list hash-list))
>  (k : Symbol (in-value (car p)))
>  (v : Natural (in-value (cdr p)))
>  #:when (not (= v 1))
>  )
>   (cons k v))
> 
> Sam
> 
> On Mon, May 18, 2020 at 4:33 PM Hendrik Boom  wrote:
> >
> > I keep getting the messages like
> >
> > Type Checker: Inference for polymorphic keyword functions not supported in: 
> > (sort hash-list string > (symbol->string (car p))) #:cache-keys? #t)
> >
> > or
> >
> > Type Checker: Polymorphic function `cons' could not be applied to arguments:
> > Types: a (Listof a) -> (Listof a)
> >a b -> (Pairof a b)
> > Arguments: (U Exact-Nonnegative-Integer Symbol) (Listof (Pairof Symbol 
> > Nonnegative-Integer))
> > Expected result: (Listof (Pairof Symbol Nonnegative-Integer))
> >  in: (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol 
> > Natural) (in-list (hash->sorted-list pname-map))) (k : Symbol (in-value 
> > (car p))) (v : Natural (in-value (cdr p))) #:when (not (= v 1)) (y (list k 
> > v))) y)
> >
> > Is there some systematic way to code this explicitly so it
> > doesn't have to try guesswork? (hich it refuses to do)
> >
> > And is it really unable to figure out that an
> > Exact-Nonnegative-Integer is a Nonnegative-Integer?
> >
> > -- hendrik
> >
> > --
> > 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.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/racket-users/20200518203342.4vcvrsrvkmld4tmh%40topoi.pooq.com.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200518221533.uwflu2ulyzeolcmv%40topoi.pooq.com.


Re: [racket-users] Inference for polymorphic functions not supported?

2020-05-18 Thread Ben Greenman
On 5/18/20, Hendrik Boom  wrote:
> I keep getting the messages like
>
> Type Checker: Inference for polymorphic keyword functions not supported in:
> (sort hash-list string (symbol->string (car p))) #:cache-keys? #t)

The way to avoid guesswork here is `inst`:

 ((inst sort (Pair Symbol Natural) String) )

Next time you see one of these errors, print the type of the function
or check the DrRacket blue box to figure out which/how many arguments
the `inst` needs.

> or
>
> Type Checker: Polymorphic function `cons' could not be applied to
> arguments:
> Types: a (Listof a) -> (Listof a)
>a b -> (Pairof a b)
> Arguments: (U Exact-Nonnegative-Integer Symbol) (Listof (Pairof Symbol
> Nonnegative-Integer))
> Expected result: (Listof (Pairof Symbol Nonnegative-Integer))
>  in: (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol Natural)
> (in-list (hash->sorted-list pname-map))) (k : Symbol (in-value (car p))) (v
> : Natural (in-value (cdr p))) #:when (not (= v 1)) (y (list k v))) y)
>
> Is there some systematic way to code this explicitly so it
> doesn't have to try guesswork? (hich it refuses to do)
>
> And is it really unable to figure out that an
> Exact-Nonnegative-Integer is a Nonnegative-Integer?

This looks like a genuine type error, because (U
Exact-Nonnegative-Integer Symbol) is not a Pair.

Should the loop body say `p` instead of `y`?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R7v4wnd9WrOdNEd6f4oTn5oGhPbe%3DtSgympmDuPQt0N3A%40mail.gmail.com.


[racket-users] Inference for polymorphic functions not supported?

2020-05-18 Thread Hendrik Boom
I keep getting the messages like

Type Checker: Inference for polymorphic keyword functions not supported in: 
(sort hash-list stringstring 
(car p))) #:cache-keys? #t)

or

Type Checker: Polymorphic function `cons' could not be applied to arguments:
Types: a (Listof a) -> (Listof a)
   a b -> (Pairof a b)
Arguments: (U Exact-Nonnegative-Integer Symbol) (Listof (Pairof Symbol 
Nonnegative-Integer))
Expected result: (Listof (Pairof Symbol Nonnegative-Integer))
 in: (for*/list : (Listof (Pair Symbol Natural)) ((p : (Pair Symbol Natural) 
(in-list (hash->sorted-list pname-map))) (k : Symbol (in-value (car p))) (v : 
Natural (in-value (cdr p))) #:when (not (= v 1)) (y (list k v))) y)

Is there some systematic way to code this explicitly so it 
doesn't have to try guesswork? (hich it refuses to do)

And is it really unable to figure out that an 
Exact-Nonnegative-Integer is a Nonnegative-Integer? 

-- hendrik

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200518203342.4vcvrsrvkmld4tmh%40topoi.pooq.com.