1. You had a } mistake. 

2. You are using a polymorphic map and TR needs an additional annotation to 
figure this out: 

(: encode : (All (a) (Listof a) -> (Listof (List Nonnegative-Integer a))))

(define (encode xs)
  ({inst map (List Nonnegative-Integer a) (Listof a)}
   (λ ([ys : (Listof a)])
     (list (length ys) (first ys)))
   (pack xs)))

3. I provided a pack of type (: pack (All (a) (Listof a) -> (Listof (Listof 
a))))  

4. When you run this now, (first ys) may raise a run-time exception (just like 
in ML). 




> On May 25, 2016, at 5:31 AM, Daniel Prager <daniel.a.pra...@gmail.com> wrote:
> 
> Thanks Sam
> 
> I still get a type-checking error with
> 
> (: encode : (All (a) (Listof a) -> (Listof (List Nonnegative-Integer a))))
> 
> (define (encode xs)
>   (map (λ ([ys : (Listof a)])
>          (list (length ys) (first ys))
>        (pack xs)))) 
> 
> which I think is what you suggested. Adding a return type to the λ as well 
> yields more type errors.
> 
> 
> 
> Dan
> 
> 
> 
> On Wed, May 25, 2016 at 8:14 AM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu 
> <mailto:sa...@cs.indiana.edu>> wrote:
> What's happening here is that Typed Racket can't infer what the type
> of `ys` is in the lambda that's an argument to `map`, since you didn't
> provide an annotation. In the `for/list`, the call to `(pack xs)` is
> right there, so inference works.
> 
> To make the use of `map` work, you just annotate `ys`:  (λ ([ys :
> (Listof a)]) (list (length ys) (first ys)))
> 
> Sam
> 
> On Tue, May 24, 2016 at 5:50 PM, Daniel Prager
> <daniel.a.pra...@gmail.com <mailto:daniel.a.pra...@gmail.com>> wrote:
> > The following program works in Typed Racket, but if you comment out the
> > for/list in (encode ...) and uncomment the seemingly equivalent map it fails
> > to type check.
> >
> > Why the discrepancy and how do the experienced Typed Racketeers diagnose and
> > fix these sorts of issues?
> >
> >
> > Thanks
> >
> > Dan
> >
> >
> > P.S. These are taken from Nintey-nine Lisp Problems:
> > http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html
> >  
> > <http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html>
> >
> >
> > #lang typed/racket
> >
> > (require typed/test-engine/racket-tests)
> >
> > ;P09 (**) Pack consecutive duplicates of list elements into sublists.
> > (: pack : (All (a) (Listof a) -> (Listof (Listof a))))
> > (define (pack xs)
> >   (cond [(null? xs) null]
> >         [(null? (rest xs)) (list xs)]
> >         [else (let ([packed (pack (rest xs))]
> >                     [head (first xs)])
> >                 (if (equal? (first xs) (second xs))
> >                     (cons (cons head (first packed))
> >                           (rest packed))
> >                     (cons (list head) packed)))]))
> >
> > (check-expect (pack '(a a a a b c c a a d e e e e))
> >               '((a a a a) (b) (c c) (a a) (d) (e e e e)))
> >
> >
> > ;P10 (*) Run-length encoding of a list.
> > (: encode : (All (a) (Listof a) ->
> >                  (Listof (List Nonnegative-Integer a))))
> > (define (encode xs)
> >   #;(map (λ (ys) (list (length ys) (first ys))) (pack xs))
> >   (for/list ([ys (pack xs)])
> >     (list (length ys) (first ys))))
> >
> > (check-expect (pack '(a a a a b c c a a d e e e e))
> >               '((a a a a) (b) (c c) (a a) (d) (e e e e)))
> >
> >
> > (test)
> >
> > --
> > 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 
> > <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> > For more options, visit https://groups.google.com/d/optout 
> > <https://groups.google.com/d/optout>.
> 
> -- 
> 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 
> <mailto:racket-users+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

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

Reply via email to