Version française
Home     About     Download     Resources     Contact us    
Browse thread
From a recursive circuit to a functional/recursive OCaml-code...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] From a recursive circuit to a functional/recursive OCaml-code...
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.

Write a pure function f: S -> S representing one tick of the  
system clock.

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

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net