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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 48D93BC6B for ; Wed, 10 Oct 2007 17:56:06 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAO6SDEfLENaMn2dsb2JhbACOSAIBAQcEBgkIGA X-IronPort-AV: E=Sophos;i="4.21,255,1188770400"; d="scan'208";a="2724641" Received: from ipmail01.adl2.internode.on.net ([203.16.214.140]) by mail1-smtp-roc.national.inria.fr with ESMTP; 10 Oct 2007 17:56:05 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKaPDEd5LCRs/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.21,255,1188743400"; d="scan'208";a="207831529" Received: from ppp121-44-36-108.lns10.syd7.internode.on.net (HELO [192.168.1.201]) ([121.44.36.108]) by ipmail01.adl2.internode.on.net with ESMTP; 11 Oct 2007 01:25:57 +0930 Subject: Re: [Caml-list] Functional design for a basic simulation pipe. From: skaller To: Hugo Ferreira Cc: caml-list@yquem.inria.fr, Raj Bandyopadhyay In-Reply-To: <1192028408.6198.31.camel@rosella.wigram> References: <470C8199.4080708@inescporto.pt> <1192005274.6285.4.camel@rosella.wigram> <470CA488.1070804@inescporto.pt> <1192028408.6198.31.camel@rosella.wigram> Content-Type: text/plain Date: Thu, 11 Oct 2007 01:56:01 +1000 Message-Id: <1192031761.6728.31.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; 0100,:01 hacked:01 forall:01 forall:01 slave:98 din:98 din:98 pins:98 sourceforge:01 wrote:01 wrote:01 caml-list:01 pair:01 pair:01 int:01 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 { 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'. -- John Skaller Felix, successor to C++: http://felix.sf.net