Browse thread
From a recursive circuit to a functional/recursive OCaml-code...
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Oliver Bandel <oliver@f...> |
| Subject: | Re: [Caml-list] From a recursive circuit to a functional/recursive OCaml-code... |
On Sun, Feb 05, 2006 at 01:29:06PM +1100, skaller wrote:
> On Sat, 2006-02-04 at 22:19 +0100, Oliver Bandel wrote:
> > Hello,
> >
> >
> > how to implement a simple non-trivial machine (Heinz von Foerster)
> > in a purely functional manner?
>
> Define a record S containing your state variables.
Is it necessary to have state-variables in a record?
Is it then (with records) functional implementation?!
>
> Write a pure function f: S -> S representing one tick of the
> system clock.
Hmhhh.... ok, I see.
But I'm not clear about how to write this function "f",
because it needs mutual recursion...
In a purely impeative way I think i woulf find a solution,
but thinking about it in Ocaml => blackout. ;-(
>
> Then write
>
> let rec run f S =
> let S' = f S in
> if S' = S then S
> else run f S'
> in
> run f S0
>
> Note it may never terminate, it isn't hard to build
> an oscillator :)
Well, the run-function is not what I was looking for, because
the loop is intended to work again and again, so, it is not
necessary to have the if-then stuff inside: each clock
cycle reads in a new input-value and calculates a new output value
and then calls itself again...
and inside "f" there also is a feedback.
See the second picture in the jpeg-file:
http://www.belug.org/~ob/struktur-grafisch.jpg
Ciao,
Oliver