From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 76783BDCB for ; Wed, 31 Aug 2005 17:57:02 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7VFv1Q7009520 for ; Wed, 31 Aug 2005 17:57:01 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA03093 for ; Wed, 31 Aug 2005 17:57:01 +0200 (MET DST) Received: from alex.barettalocal.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j7VFv0uG010564 for ; Wed, 31 Aug 2005 17:57:00 +0200 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by alex.barettalocal.com (Postfix) with ESMTP id 2B9E72BAF0E; Wed, 31 Aug 2005 17:54:38 +0200 (CEST) Message-ID: <4315D2BC.9080909@barettadeit.com> Date: Wed, 31 Aug 2005 17:54:36 +0200 From: Alex Baretta User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrej Bauer Cc: Ocaml Subject: Re: [Caml-list] Restarting a piece of code References: <43107BC6.2010508@andrej.com> <431562AD.8050302@barettadeit.com> <4315B8D8.4060602@andrej.com> In-Reply-To: <4315B8D8.4060602@andrej.com> Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4315D34D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4315D34C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 caml-list:01 andrej:01 computations:01 parametric:01 rec:01 computations:01 inv:01 inv:01 monads:01 metaocaml:01 ocaml:01 andrej:01 baretta:01 thrilled:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Andrej Bauer wrote: > > Can we avoid having to pass treshold around directly? You can imagine > that users won't be too thrilled about this sort of thing. I think you can. See arithmetic functions as building blocks for computations---rather than computations themselves---which are parametric with respect to the threshold value. let unit_expression _ = assert false let imaginary_unit_expression _ = assert false let addition_expression _ = assert false let negative_expression _ = assert false let multiplication_expression _ = assert false let inverse_expression _ = assert false let exponential_expression _ = assert false let logarithm_expression _ = assert false exception Overflow let rec compute grow_threshold threshold_transformation = fun computation threshold -> try computation (compute grow_threshold) (threshold_transformation threshold) with Overflow -> let new_threshold = grow_threshold threshold in computation (compute grow_threshold) (threshold_transformation new_threshold) (* Here we define the primitive operations of the algebraic structure *) (* We don't mind if the primitive operations are a little heavy, so *) (* long as it is easy to compose them to form complex computations. *) let one = fun compute threshold -> unit_expression threshold let i = fun compute threshold -> imaginary_unit_expression threshold let add x y = fun compute threshold -> let x' = compute x threshold in let y' = compute y threshold in addition_expression x y threshold let neg x = fun compute threshold -> let x' = compute x threshold in negative_expression x threshold let mul x y = fun compute threshold -> let x' = compute x threshold in let y' = compute y threshold in multiplication_expression x y threshold let inv x = fun compute threshold -> let x' = compute x threshold in inverse_expression x threshold let exp x = fun compute threshold -> let x' = compute x threshold in exponential_expression x threshold let log x = fun compute threshold -> let x' = compute x threshold in logarithm_expression x threshold (* Let's say these are all the basic computations we need. Now we can *) (* start building more computations on top of these. *) let sub x y = add x (neg y) let div x y = mul x (inv y) let pow x y = exp (mul (log x) y) let root x y = exp (mul (log x) (inv y)) let two = add one one let twoi = add i i let cos x = div (add (exp (mul i x)) (exp (neg (mul i x)))) two let sin x = div (sub (exp (mul i x)) (exp (neg (mul i x)))) twoi > I sense monads. Or am I looking for dynamic binding? You are looking for partial evaluation/multistage programming, but you don't necessarily have to delve into MetaOcaml to solve your problem. As you can see you can generate a homomorphism from the calculus of imaginary numbers to the calculus of computations of imaginary numbers which can be directly represented in Ocaml. > Best regards, > > Andrej > -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project