[racket-dev] more general typed/scheme bafflement...

2011-06-07 Thread John Clements
I see that map works on multiple lists in at least one circumstance, e.g. (map 
+ (list 3 4) (list 4 5)).  I couldn't get it to work with "list", though, even 
when I specialized list to a two-argument function:

#lang typed/racket

(: list2 (All (T) (T T -> (List T T
(define (list2 a b) (list a b))

(map list2 '(3 4 5) '(10 11 12))

==> Type Checker: Polymorphic function map could not be applied to arguments:
Domains: (a -> c) (Pairof a (Listof a))
 (a b ... b -> c) (Listof a) (Listof b) ... b
Arguments: (All (T) (T T -> (List T T))) (List Positive-Byte Positive-Byte 
Positive-Byte) (List Positive-Byte Positive-Byte Positive-Byte)
 in: (map list2 (quote (3 4 5)) (quote (10 11 12)))

Is there some easy fix here?

Also, I am deeply confused by the second of those domains, that makes it appear 
that I'm supposed apply map to a bunch of lists and then to a bare "b".

John



smime.p7s
Description: S/MIME cryptographic signature
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] more general typed/scheme bafflement...

2011-06-07 Thread Carl Eastlund
John,

You had an easy time with + because it is monomorphic.  You are having
trouble applying one polymorphic function (map) to another (list or
list2).  Instantiate one or both functions explicitly, and Typed
Racket won't get confused by the guesswork.

Also, T ... i in a type does not mean T ... followed by i.  It means T
... *indexed* by i.  It's clarifying what the ... ranges over.

Carl Eastlund

On Tue, Jun 7, 2011 at 7:16 PM, John Clements  wrote:
> I see that map works on multiple lists in at least one circumstance, e.g. 
> (map + (list 3 4) (list 4 5)).  I couldn't get it to work with "list", 
> though, even when I specialized list to a two-argument function:
>
> #lang typed/racket
>
> (: list2 (All (T) (T T -> (List T T
> (define (list2 a b) (list a b))
>
> (map list2 '(3 4 5) '(10 11 12))
>
> ==> Type Checker: Polymorphic function map could not be applied to arguments:
> Domains: (a -> c) (Pairof a (Listof a))
>         (a b ... b -> c) (Listof a) (Listof b) ... b
> Arguments: (All (T) (T T -> (List T T))) (List Positive-Byte Positive-Byte 
> Positive-Byte) (List Positive-Byte Positive-Byte Positive-Byte)
>  in: (map list2 (quote (3 4 5)) (quote (10 11 12)))
>
> Is there some easy fix here?
>
> Also, I am deeply confused by the second of those domains, that makes it 
> appear that I'm supposed apply map to a bunch of lists and then to a bare "b".
>
> John
>
>
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev
>

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] more general typed/scheme bafflement...

2011-06-07 Thread John Clements

On Jun 7, 2011, at 4:26 PM, Carl Eastlund wrote:

> John,
> 
> You had an easy time with + because it is monomorphic.  You are having
> trouble applying one polymorphic function (map) to another (list or
> list2).  Instantiate one or both functions explicitly, and Typed
> Racket won't get confused by the guesswork.
> 
> Also, T ... i in a type does not mean T ... followed by i.  It means T
> ... *indexed* by i.  It's clarifying what the ... ranges over.

Awesome! Many thanks. Next question.  I'm reading sexps from a file, so 
typed/racket insists that I check their shape before using them.  That's fine, 
but I find myself unable to define the "(Pairof Any (Pairof Any Null)) 
predicate the way I'd expect it to be defined:

(: listoflength2? (Any -> Boolean : (Pairof Any (Pairof Any Null
(define (listoflength2? a)
  (and (pair? a) (pair? (cdr a)) (null? (cddr a

=> 

Type Checker: Expected result with filter (((List Any Any) @ a) | (! (List Any 
Any) @ a)), got filter ((AndFilter (Null @ (cdr cdr) a) ((Pairof Any Any) @ 
(cdr) a) ((Pairof Any Any) @ a)) | (OrFilter (! Null @ (cdr cdr) a) (! (Pairof 
Any Any) @ (cdr) a) (! (Pairof Any Any) @ a))) in: (and (pair? a) (pair? (cdr 
a)) (null? (cddr a)))
> 

This is curious, because the text '(AndFilter (Null @ (cdr cdr) a) ((Pairof Any 
Any) @ (cdr) a) ((Pairof Any Any) @ a)) ' looks like it's saying exactly what 
'(Pairof Any (Pairof Any Null))' does.

Again, any help appreciated.  This typed racket stuff is *way* more fun than 
the actual grading that the script is supposed to be helping me with... :).

John



smime.p7s
Description: S/MIME cryptographic signature
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] more general typed/scheme bafflement...

2011-06-07 Thread Sam Tobin-Hochstadt
On Tue, Jun 7, 2011 at 4:57 PM, John Clements  wrote:
>
> On Jun 7, 2011, at 4:26 PM, Carl Eastlund wrote:
>
>> John,
>>
>> You had an easy time with + because it is monomorphic.  You are having
>> trouble applying one polymorphic function (map) to another (list or
>> list2).  Instantiate one or both functions explicitly, and Typed
>> Racket won't get confused by the guesswork.
>>
>> Also, T ... i in a type does not mean T ... followed by i.  It means T
>> ... *indexed* by i.  It's clarifying what the ... ranges over.
>
> Awesome! Many thanks. Next question.  I'm reading sexps from a file, so 
> typed/racket insists that I check their shape before using them.  That's 
> fine, but I find myself unable to define the "(Pairof Any (Pairof Any Null)) 
> predicate the way I'd expect it to be defined:

What you actually want to use here is `define-predicate', which will
automatically define the predicate you want given the type.

>
> (: listoflength2? (Any -> Boolean : (Pairof Any (Pairof Any Null
> (define (listoflength2? a)
>  (and (pair? a) (pair? (cdr a)) (null? (cddr a

This definition will eventually typecheck, but not yet.  :)

-- 
sam th
sa...@ccs.neu.edu

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev