From: Hugo Ferreira <hmf@inescporto.pt>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list@yquem.inria.fr, Raj Bandyopadhyay <rajb@rice.edu>
Subject: Re: [Caml-list] Functional design for a basic simulation pipe.
Date: Thu, 11 Oct 2007 07:57:33 +0100 [thread overview]
Message-ID: <470DC95D.8020701@inescporto.pt> (raw)
In-Reply-To: <1192031761.6728.31.camel@rosella.wigram>
Hello,
skaller wrote:
> 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 ->+
> ^ |
> | |
> +--------<---------+
>
Basically yes. Closer to this though:
a -> b -> c -> d ->+-> e -> f
^ |
| |
+--------<---------+
The solution below is basically the same suggestion I got (in Ocaml)
from someone else. I guess this is the way to go then.
Regards,
Hugo F.
> ////////////////////////////////////////////////////
> // generate events 1 to limit
> proc a
> (
> limit:ischannel[int],
> chout: oschannel[int]
> )
> {
> var event:int; var n:int;
> forever {
> read(&n,limit);
> forall event in 1 upto n do
> write(chout,event);
> done;
> };
> }
>
> // double it
> proc b(chin: ischannel[int], chout: oschannel[int]) {
> int event;
> forever {
> read(&event,chin);
> write(chout,event*2);
> };
> }
>
> // add 1
> proc c(chin: ischannel[int], chout: oschannel[int]) {
> int event;
> forever {
> read(&event,chin);
> 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
> read(&event, chin);
> //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]();
> spawn_fthread { a(limin, aout); };
> spawn_fthread { b(bin, bout); };
> spawn_fthread { c(cin, cout); };
> spawn_fthread { d(din, limout); };
> }
>
> 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'.
>
>
next prev parent reply other threads:[~2007-10-11 6:59 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-10 7:39 Hugo Ferreira
2007-10-10 8:34 ` [Caml-list] " skaller
2007-10-10 10:08 ` Hugo Ferreira
2007-10-10 10:31 ` Vincent Aravantinos
2007-10-10 10:56 ` Hugo Ferreira
2007-10-11 12:01 ` Pietro Abate
2007-10-11 13:52 ` Hugo Ferreira
2007-10-11 14:20 ` Pietro Abate
2007-10-10 15:00 ` skaller
2007-10-10 15:56 ` skaller
2007-10-11 6:57 ` Hugo Ferreira [this message]
2007-10-11 8:09 ` skaller
2007-10-11 9:54 ` Hugo Ferreira
2007-10-11 13:47 ` skaller
2007-10-11 11:17 ` Zheng Li
2007-10-11 13:48 ` [Caml-list] " Hugo Ferreira
2007-10-15 23:04 ` Zheng Li
2007-10-22 7:48 ` [Caml-list] " Hugo Ferreira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=470DC95D.8020701@inescporto.pt \
--to=hmf@inescporto.pt \
--cc=caml-list@yquem.inria.fr \
--cc=rajb@rice.edu \
--cc=skaller@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox