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.3 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 284DFBC6B for ; Wed, 10 Oct 2007 09:39:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADseDEfAI/YBnWdsb2JhbACBWoxuAgEBCw8I X-IronPort-AV: E=Sophos;i="4.21,252,1188770400"; d="scan'208";a="17784962" Received: from ns.inescn.pt (HELO animal.inescn.pt) ([192.35.246.1]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Oct 2007 09:39:34 +0200 Received: from localhost (localhost [127.0.0.1]) by animal.inescn.pt (8.13.8/8.13.6/9) with ESMTP id l9A7dWmE008435 for ; Wed, 10 Oct 2007 08:39:33 +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 gTPrkCa3v3aD for ; Wed, 10 Oct 2007 08:39:12 +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 l9A7d91e008407 for ; Wed, 10 Oct 2007 08:39:11 +0100 (WEST) Message-ID: <470C8199.4080708@inescporto.pt> Date: Wed, 10 Oct 2007 08:39:05 +0100 From: Hugo Ferreira User-Agent: Thunderbird 2.0.0.6 (X11/20070806) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Functional design for a basic simulation pipe. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; val:01 val:01 pulled:98 terminate:01 termination:01 termination:01 lazy:02 data:02 data:02 exp:02 exp:02 defined:02 functional:02 functional:02 unit:03 Hello, I have been looking at how I may go about developing a very simple simulation system for my experiments. The simulation consists in generating a set of events, these events then cause a state change, the state change is then analyzed and processed in several steps and finally termination conditions are checked. When said termination condition is true the simulation ends and the results are saved. Now I figured this could be done using composition. For example: # let ( |> ) f g x = g (f x) ;; val ( |> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c = # let gen_events s0 = () ;; val gen_events : 'a -> unit = # let gen_states e = () ;; val gen_states : 'a -> unit = # let analyze_data s = () ;; val analyze_data : 'a -> unit = # let check_stop s = () ;; val check_stop : 'a -> unit = Then I could set-up an experiment so: # let exp = gen_events |> gen_states |> analyze_data |> check_stop ;; val exp : '_a -> unit = And execute it so: # let start_state = () ;; val start_state : unit = () # let _ = exp start_state ;; - : unit = () Please note that I have used any old types just to get the idea through. Also note that experiments are set-up with a given set of parameters. Such parameters can be defined when the "exp" composition is set up. Ok, so far so good. Now notice how the data events and state change are potentially infinite. I figured the best way to go about it is with lazy evaluation so that the calculations terminate when the last function in the pipe stop "pulling" data in. This is all "fine and dandy" but the problem I have however is that the "gen_events" function depends on the last state reached. In other words "gen_states" updates the current state which should then be made available to "gen_events" when the next events are "pulled in". Of course this could be solved with a global reference but this is not functional. Alternatively we could combine "gen_events" and "gen_state" into one function (my best bet?). 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? TIA, Hugo F.