English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2006-02-05 (02:29)
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