Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Functional design for a basic simulation pipe.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-10-11 (11:16)
From: Zheng Li <li@p...>
Subject: Re: Functional design for a basic simulation pipe.

Hugo Ferreira <> writes:
> My question is: how can one design and implement such a "pull pipe" and
> solve the problem I have of propagating state back to a previous
> function. If this is not possible functionally what other options do I
> have? Better yet, what is the better way to implement such a system?

It seems that you want to program in a dataflow paradigm in OCaml. You don't
have to use concurrent programming if you find it heavyweight, instead you
should use stream (or lazy, or other sth alike) which is already provided by

Usually, you'll define a set of combinators include: map, dup, pipe, filter,
until, combine/split, merge/switch etc to facile your work. The only difficulty
I can foresee is that OCaml only supports recursive value in a quite restrictive
form. E.g. 

  let rec s = [<'1; s>]   or   let rec s1 = [<'1; s2>] and s2 = map f s1

is not directly supported. One can make use of recursive function as
workaround, but the semantics may not always identical.  However, if you have
control over your data structure, you can usually define your specific version
of stream type, then this won't be a problem any more. 

In some dataflow languages I know, such kind of recursion is often represented
through a special form -- "delay" which is provided as system primitive. If
written in plain OCaml, the "delay" primitive won't be combinatorial as you
want, so you have to require programmers to handle it specially. Fortunately,
in most cases, a higer-level combinatorial form is usually sufficient, so that
you can use it to hide the "delay" with sth like "recur".

IIRC, OCaml was uses as the basis of some dataflow languages developed in
french universities. Maybe they can give you more suggestions.


Zheng Li