Ok, it took me a while to see how to eliminate the apply:

(define-syntax-rule (table (a ...) body)
  (for/list : (Listof (Listof Boolean))
    ([b : (Listof Boolean) (boolean-tuple (length '(a ...)))])
    (match-define (list a ...) b)
    (append b (list ((λ ([a : Boolean] ...) : Boolean
                       body) a ...)))))


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 <http://www.youpatch.com>, skillfire.co
Twitter: @agilejitsu <https://twitter.com/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