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

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: -- (:) From: skaller Subject: Re: [Caml-list] Functional design for a basic simulation pipe.
```On Thu, 2007-10-11 at 01:00 +1000, skaller wrote:
> On Wed, 2007-10-10 at 11:08 +0100, Hugo Ferreira wrote:
> > Hello,
>
> >
> > Apologies for being so obtuse but I cannot to see how this solves my
> > problem.
>
> > let exp = a |> b |> c

> A function is a slave, it is *called* with its argument.
> you cant *read* the arguments.

BTW: what you want is something like this 'concept demo'
I hacked up in Felix (notes below).

a -> b -> c -> d ->+
^                  |
|                  |
+--------<---------+

////////////////////////////////////////////////////
// generate events 1 to limit
proc a
(
limit:ischannel[int],
chout: oschannel[int]
)
{
var event:int; var n:int;
forever {
forall event in 1 upto n do
write(chout,event);
done;
};
}

// double it
proc b(chin: ischannel[int], chout: oschannel[int]) {
int event;
forever {
write(chout,event*2);
};
}

proc c(chin: ischannel[int], chout: oschannel[int]) {
int event;
forever {
write(chout,event+1);
};
}

proc d
(
chin:ischannel[int],
limit: oschannel[int]
)
{
int count; int i; int event;
var total = 10;
while (total < 1000) {
println\$ "subtotal " + str total;
n := total;
write(limit,total);
forall i in 1 upto n do
//println\$ f"Event %d = %d" (i,event);
total += event;
done;
};
println\$ "total=" + str total;
}

proc pipeline() {
bin,aout := mk_ioschannel_pair[int]();
cin,bout := mk_ioschannel_pair[int]();
din,cout := mk_ioschannel_pair[int]();
limin,limout := mk_ioschannel_pair[int]();
}

pipeline();
///////////////////////////////////////
\$ f fl
subtotal 10
subtotal 130
total=17290
////////////////////////////////////////

Here we create procedures a,b,c,d which are templates
for "chips" with input and output "pins".

In the pipeline() procedure we create wires with named ends for input
and output, and plug them into instances of the 'chips'
to create a 'circuit'. (This is crude but it works and is
fully general).

In the pipeline the input state of 'a' is the 'limit' value,
which is written by 'd'. When 'd' gets the result sum, if it is
too small it writes the sum as the new limit back to the
chip 'a'.

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

```