[PRL] Type question...

Sam TH samth at ccs.neu.edu
Wed Oct 3 23:50:18 EDT 2007


Just as a further demonstration, here's your code in Typed Scheme:

(let ((fact (lambda: ([num : Number])
               ((lambda: ([f : (mu Z (Z Number -> Number))] [n :
Number]) (f f n))
                (lambda: ([g : (mu Z (Z Number -> Number))] [m : Number])
                  (if (< m 2) 1
                      (* m (g g (- m 1))))) num))))
  (fact 5))

sam th

On 10/3/07, Riccardo Pucella <riccardo at ccs.neu.edu> wrote:
> >> (let ((fact (lambda (num)
> >>                 ((lambda (f n) (f f n))
> >>                  (lambda (g m)
> >>                    (if (< m 2) 1
> >>                        (* m (g g (- m 1))))) num))))
> >>    (fact 5))
>
> > I believe it's the (f f n) and (g g (- m 1)) that shoot you down.
> > There's no simple type for a function that accepts itself as an
> > argument.
>
> Right; as Carl says, just look at (lambda (f n) (f f n))
>
> The best type you could give it is the recursive type:
>    (\mu Z.( Z x a -> b)) x a -> b
>
> (Where a is the type of n, and b is the result type of the lambda.
>
>   Cheers,
>   R
>
>
>
>
> _______________________________________________
> PRL mailing list
> PRL at lists.ccs.neu.edu
> https://lists.ccs.neu.edu/bin/listinfo/prl
>


-- 
sam th
samth at ccs.neu.edu



More information about the PRL mailing list