caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] From a recursive circuit to a functional/recursive OCaml-code...]
@ 2006-02-05  4:03 Oliver Bandel
  0 siblings, 0 replies; only message in thread
From: Oliver Bandel @ 2006-02-05  4:03 UTC (permalink / raw)
  To: caml-list

Hello,


On Sun, Feb 05, 2006 at 12:36:53PM +1300, Jonathan Roewen wrote:
> Where does the iterating come in? From your description, all you're
> doing is a one-time calculation on a set of input values.

u is calculated out of e and x with operator/function function_B.

But e is calculated out of u with function_C

So, there is a loop of calculation, which means that there is recursion...



> 
> E.g. of the form:
> 
> while true do
>    print_result (func_A (read_int ()))
> done;;

Yes, that's, what is the underlying thing: you get input values and
create output values.

But the calculation of output values is done via an internal feedback...



> 
> Perhaps if you upload the circuit somewhere so people can see, it
> might make a difference.

OK, because sending it as an email-attachement didn't worked on this list,
I put the picture here:

   http://www.belug.org/~ob/struktur-grafisch.jpg

The first picture is the so called trivial machine,
which only operates on the input with an operation/function
and creates an output value;
and the second picture in the file is the non-trivial machine
(the simplest version of a non-trivial machine with one input value
 and the necessary feedback inside the machine).

(Distinction between both is done because: the non-trivial machine is
 history dependnt, the trivial is not. Also there are differences in
 prediction of both: the trivial machine is time-independent and therefore
 easily to predict. But the non-trivial machine can't be tested/analyzed/predicted
 as like the trivial machine...)

For the trivial machine I had done two implementations: one is iterative
and uses the while-loop. And then I did a recursive implementation.

For the trivial machine (first picture) I created the following code
that is functional/recursive:


(* -------------------------------------------- *)

let function_A x =  x * 2

let _ =
  let rec calc () =
    let inval = int_of_string (read_line()) (* input-value "x" in the picture *)
    in
      let outval = function_A inval (* Operator/Function "A" in the picture *)
      in
        Printf.printf "%d => %d \n" inval outval; calc() (* outval is "y" in the picture *)
  in
    calc ()
      
(* -------------------------------------------- *)



For the non-trivial machine because of the feedbacks it's
not so easy to write it as a program.
IMHO FP has some advantages, because I do not need to store
transitional valuthe necessaryes... but the recursions stuff.... welll, how to implement it here?!

I had tried some ways (mutual recursive functions, mutual values
and combinations, but I don't know what I really need and
I need some help here....).


TIA,
   Oliver


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-05  4:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-05  4:03 [Caml-list] From a recursive circuit to a functional/recursive OCaml-code...] Oliver Bandel

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).