The easiest way to avoid this is to program with the types, and the
type checker, in mind from the start. If you write a maximally-clever
Racket program, and then try to get it to type check, you will
probably need to change it.

Also, I expect that those problems in particular seem to involve a lot
of punning back and forth between lists as sequences and lists as
fixed-length data, which is the sort of traditional lisp & scheme
style that is unlikely to work well in Typed Racket. So that might not
be the best place to start.

Sam

On Fri, Jun 10, 2016 at 6:09 PM, Daniel Prager
<daniel.a.pra...@gmail.com> wrote:
> Thanks Sam
>
> I seem to repeatedly come up against this sort of problem, where I can make
> inferences that are beyond the ken of Typed Racket.
>
> Do you have general advice, given TR's "by design" conservatism?
>
> Dan
>
>
> On Sat, Jun 11, 2016 at 7:47 AM, Sam Tobin-Hochstadt <sa...@cs.indiana.edu>
> wrote:
>>
>> The problem here is that you have a fixed-argument function (taking 3
>> Boolean arguments) and you're applying it to a list of unknown length. Your
>> program knows that this won't be a problem, because `boolean-tuple` always
>> produces a list of exactly the right length, but Typed Racket doesn't know
>> that.
>>
>> Sam
>>
>> On Fri, Jun 10, 2016 at 5:39 PM Daniel Prager <daniel.a.pra...@gmail.com>
>> wrote:
>>>
>>> I'm working my way through the 99 Lisp Problems
>>> (http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
>>> to improve my proficiency with Typed Racket.
>>>
>>> While sometimes the discipline of the types helps me catch mistakes,
>>> quite often I find myself wrestling to get through the type-check.
>>>
>>> My tactics to get things working include: dropping back to Racket to make
>>> the program work first, switching between for/... and recursive forms,
>>> widening the type (e.g. from Natural to Integer), and using cast.
>>>
>>> I'll post some examples of where I've struggled (or am struggling). First
>>> example below.
>>>
>>> Tips and strategies gratefully accepted!
>>>
>>> Dan
>>>
>>>
>>> The first example writes out truth tables for a boolean expression with
>>> an arbitrary number of parameters.
>>>
>>> E.g.
>>>
>>> > (table (a b c) (equal? (and a (or b c))
>>>                          (or (and a b)
>>>                              (and a c))))
>>> ;  a  b  c  result
>>> ;
>>> '((#t #t #t #t)
>>>   (#t #t #f #t)
>>>   (#t #f #t #t)
>>>   (#t #f #f #t)
>>>   (#f #t #t #t)
>>>   (#f #t #f #t)
>>>   (#f #f #t #t)
>>>   (#f #f #f #t))
>>>
>>>
>>> Works in Racket:
>>>
>>> #lang racket
>>>
>>> ;P48 (**) Truth tables for logical expressions (3).
>>>
>>> (define (boolean-tuple n)
>>>   (if (= n 1)
>>>       '((#t) (#f))
>>>       (for*/list
>>>         ([a '(#t #f)] [t (boolean-tuple (sub1 n))])
>>>         (cons a t))))
>>>
>>> (define-syntax-rule (table (a ...) body)
>>>   (for/list
>>>     ([b (boolean-tuple (length '(a ...)))])
>>>     (append b (list (apply (λ (a ...)
>>>                              body)
>>>                            b)))))
>>>
>>>
>>> Can't get past type-check in TR:
>>>
>>> #lang typed/racket
>>>
>>>
>>> (define (boolean-tuple [n : Integer]) : (Listof (Listof Boolean))
>>>   (if (= n 1)
>>>       '((#t) (#f))
>>>       (for*/list : (Listof (Listof Boolean))
>>>         ([a '(#t #f)] [t (boolean-tuple (sub1 n))])
>>>         (cons a t))))
>>>
>>> (define-syntax-rule (table (a ...) body)
>>>   (for/list : (Listof (Listof Boolean))
>>>     ([b : (Listof Boolean) (boolean-tuple (length '(a ...)))])
>>>     (append b (list (apply (λ ([a : Boolean] ...) : Boolean
>>>                              body)
>>>                            b)))))
>>>
>>> Type Checker: Bad arguments to function in `apply':
>>> Domain: Boolean Boolean Boolean
>>> Arguments: (Listof Boolean) *
>>>  in: (apply (λ ((a : Boolean) ...) : Boolean body) b)
>>>
>>> --
>>> 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.
>
>
>
>
> --
> Daniel Prager
> Agile/Lean Coaching, Innovation, and Leadership
> Profile: skillfire.co/dan
> Startups: youpatch.com, skillfire.co
> Twitter: @agilejitsu
> Blog: agile-jitsu.blogspot.com
> Linkedin: au.linkedin.com/in/danielaprager

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