Version française
Home     About     Download     Resources     Contact us    
Browse thread
weird type behavior
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kirill <kirillkh@g...>
Subject: Re: [Caml-list] weird type behavior
Here's the same code as in my second message, in shorter and arguably
more readable form. createln function creates a Church's "lambda
number". succ and pred, respectively, produce successive and preceding
numbers to the given.


let rec createln = function
  | 0 -> fun f x -> x
  | n -> fun f x -> f (createln (n-1) f x)
;;

let succ lnum f x = f (lnum f x);;

let pred lnum =
  let calc_last_pair =
    lnum (
      fun pair ->
        let curr = car pair in
          cons (succ curr) curr
    ) (
      cons (createln 0) (createln 0)
    )
  in cdr calc_last_pair
;;


On Sun, 2006-10-29 at 03:12 +0200, Kirill wrote:
> Hi,
> 
> Unfortunately, I wasn't able to infer, how to solve my problem from the
> FAQ, nor from other sources. I can see that partial application somehow
> interferes with polymorphism, and partial application does look
> necessary for my task. Does it mean it's completely impossible in OCaml?
> Or is there still some way to overcome the problem?
> 
> -Kirill
> 
> 
> On Sun, 2006-10-29 at 03:05 +0200, Kirill wrote:
> > On Sat, 2006-10-28 at 17:15 +0100, Richard Jones wrote:
> > > I think the answer to the second part of your question is here:
> > > 
> > > http://caml.inria.fr/resources/doc/faq/core.en.html#eta-expansion
> > > 
> > > Rich.
> > >