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.3 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 342D5BBC1 for ; Mon, 24 Mar 2008 22:56:11 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjoBANe/50fOvjGtfGdsb2JhbACRFwEBCwUCBwcWlnk X-IronPort-AV: E=Sophos;i="4.25,548,1199660400"; d="scan'208";a="24134401" Received: from web54603.mail.re2.yahoo.com ([206.190.49.173]) by mail4-smtp-sop.national.inria.fr with SMTP; 24 Mar 2008 22:56:10 +0100 Received: (qmail 43802 invoked by uid 60001); 24 Mar 2008 21:56:09 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=H/OjXMbmZdnNRxsSGdbJYSD035vNfgtoraAJsD690R8ENhVJ/Lt0f9bx3RXTWVseVMpdYJ4Z9d82mg/PqMpN4qdoqcMhe+S5uexIu/2o8q/ir5LJ9FibaXhbOLGEUEsWPaH4rJP8uxrwX8Euw98V2qXqcAlRuzw27z1nqMYhMGc=; X-YMail-OSG: 2gddjnkVM1kBFqG2ANoP1RMt4crGtlMzGH8jq0C3se_6YAFWeIjT3gtftGJLi9Eeg.AaWb_sMkC93mzuekoFcWURSKcSvJNJybXUiq9nREcSq36qUqyI35uZuH3Eew-- Received: from [85.240.114.11] by web54603.mail.re2.yahoo.com via HTTP; Mon, 24 Mar 2008 21:56:09 GMT Date: Mon, 24 Mar 2008 21:56:09 +0000 (GMT) From: Dario Teixeira Subject: Sources, sinks, and unbound parameter types To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <535050.42465.qm@web54603.mail.re2.yahoo.com> X-Spam: no; 0.00; node:01 transforming:01 ocaml:01 node:01 nodes:01 inputs:01 inputs:01 printf:01 printf:01 compiler:01 statically:01 syntax:01 ocaml:01 connectors:98 2.0:98 Hi, I'm looking for a way to express the composition of functional components in a tree-like data structure. Each node in the tree is either: a) a Source, producing values "out of nowhere": unit -> 'a b) a Sink, end point of the tree: 'b -> unit c) a Processor, transforming values from one type to another: 'c -> 'd The Ocaml type that represents a node is as follows: (pretty straightforward, though I wonder if there's a way to explicitly say that "Source is of 'a -> 'b where 'a must be of type unit") type ('a, 'b) node_t = | Source of (unit -> 'b) | Sink of ('a -> unit) | Processor of ('a -> 'b) In addition, there are two types of connectors linking these nodes in the tree: a) a Pipe, connecting one node that outputs a value of type 'a into another that inputs an 'a. b) a Splitter, essentially like a Pipe, but able to feed the same value into multiple inputs. If you'll pardon the ASCII art, here's a diagram of one such simple tree: | =========== | | source1 | | =========== | | | | | O Pipe | | | | | ============ | | process1 | | ============ | | | | | ----------------O---------------- | | Splitter | | | | | =========== =========== | | sink1 | | sink2 | | =========== =========== Where each component node can, for example, be defined as follows: let source1 () = 10 let process1 n = 2.0 *. (float_of_int n) let sink1 x = Printf.printf "Sink1: %f\n" x let sink2 x = Printf.printf "Sink2: %f\n" x To define the tree type, I would like to express something like the code below. Note that I am trying to get to the compiler to statically enforce that outputs and inputs are correctly matched type-wise. type ('a, 'b) tree_t = | Node of ('a, 'b) node_t | Pipe of ('a, 'c) tree_t * ('c, 'b) tree_t | Splitter of ('a, 'c) tree_t * ('c, 'b) tree_t list The code above obviously won't work because of the unbound type parameter 'c. (Also, please ignore for now the fact it allows splitters with an empty output list -- that can easily be circumvented). So, my question is if there is any way to express what I want? I guess there is a solution involving the creation of a syntax extension, but I'm looking for a pure Ocaml way. Thanks in advance for your time! Best regards, Dario Teixeira ___________________________________________________________ Rise to the challenge for Sport Relief with Yahoo! For Good http://uk.promotions.yahoo.com/forgood/