caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Baretta <alex@barettadeit.com>
To: Andrej Bauer <Andrej.Bauer@andrej.com>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Restarting a piece of code
Date: Wed, 31 Aug 2005 17:54:36 +0200	[thread overview]
Message-ID: <4315D2BC.9080909@barettadeit.com> (raw)
In-Reply-To: <4315B8D8.4060602@andrej.com>

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)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


      parent reply	other threads:[~2005-08-31 15:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-27 14:42 Andrej Bauer
2005-08-31  7:56 ` [Caml-list] " Alex Baretta
     [not found]   ` <4315B8D8.4060602@andrej.com>
2005-08-31 15:54     ` Alex Baretta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4315D2BC.9080909@barettadeit.com \
    --to=alex@barettadeit.com \
    --cc=Andrej.Bauer@andrej.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).