From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 33472BC6B for ; Thu, 11 Oct 2007 08:59:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAABpmDUfAI/YBnWdsb2JhbACBWoxwAQEBAQsPCA X-IronPort-AV: E=Sophos;i="4.21,257,1188770400"; d="scan'208";a="17828051" Received: from ns.inescn.pt (HELO animal.inescn.pt) ([192.35.246.1]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Oct 2007 08:59:13 +0200 Received: from localhost (localhost [127.0.0.1]) by animal.inescn.pt (8.13.8/8.13.6/9) with ESMTP id l9B6vvMJ001735; Thu, 11 Oct 2007 07:57:57 +0100 (WEST) X-Virus-Scanned: amavisd-new at inescporto.pt Received: from animal.inescn.pt ([127.0.0.1]) by localhost (animal.inescn.pt [127.0.0.1]) (amavisd-new, port 10024) with LMTP id j5gBwjFb1Sxn; Thu, 11 Oct 2007 07:57:36 +0100 (WEST) Received: from [194.117.30.94] (morfina.inescn.pt [194.117.30.94]) by animal.inescn.pt (8.13.8/8.13.8/26) with ESMTP id l9B6vXgw001725; Thu, 11 Oct 2007 07:57:33 +0100 (WEST) Message-ID: <470DC95D.8020701@inescporto.pt> Date: Thu, 11 Oct 2007 07:57:33 +0100 From: Hugo Ferreira User-Agent: Thunderbird 2.0.0.6 (X11/20070806) MIME-Version: 1.0 To: skaller Cc: caml-list@yquem.inria.fr, Raj Bandyopadhyay Subject: Re: [Caml-list] Functional design for a basic simulation pipe. References: <470C8199.4080708@inescporto.pt> <1192005274.6285.4.camel@rosella.wigram> <470CA488.1070804@inescporto.pt> <1192028408.6198.31.camel@rosella.wigram> <1192031761.6728.31.camel@rosella.wigram> In-Reply-To: <1192031761.6728.31.camel@rosella.wigram> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 0100,:01 hacked:01 ocaml:01 forall:01 forall:01 slave:98 din:98 din:98 pins:98 wrote:01 wrote:01 caml-list:01 pair:01 pair:01 int:01 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'. > >