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: | 2006-02-05 (18:07) |
From: | Oliver Bandel <oliver@f...> |
Subject: | Re: [Caml-list] From a recursive circuit to a functional/recursive OCaml-code... |
On Mon, Feb 06, 2006 at 03:05:45AM +1100, skaller wrote: > On Sun, 2006-02-05 at 15:17 +0100, Oliver Bandel wrote: > > Looking at > > http://www.belug.org/~ob/struktur-grafisch.jpg > > the bottom diagram, I would do this: > > type state = { e:t; u:t } > > for some type t I don't know about, possibly the types > are different, but this will do for exposition. > > You also have arrows > > a: t * t -> t > b: t * t -> t > c: t -> t [...] Ah, OK, that's fine to start with the type! :) Starting the task with the type clarifies a lot! :) > > So the clock function is simply > > let step (s:state) x = > { s with > e = c s.u; > u = b (x, s.e) > } > in s, a (x, s.e) OK, that's nice... I had forgotten how (but knew that I once knew that it must be possible) to make a functional record-update-copy. The "with" keyword is a fine thing. :) Looks so much smaller the code, much nicer than the let...in stuff :) > > This function accepts the state and a new input x, > and returns the state and the output y. OK, I will explore it. Thanks. Ciao, Oliver