From: "Christopher L Conway" <cconway@cs.nyu.edu>
To: "Dario Teixeira" <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Sources, sinks, and unbound parameter types
Date: Mon, 24 Mar 2008 18:19:14 -0400 [thread overview]
Message-ID: <4a051d930803241519j36c2cc7cm7d3cb745acaa6af@mail.gmail.com> (raw)
In-Reply-To: <535050.42465.qm@web54603.mail.re2.yahoo.com>
This looks a lot like the "Lists of Composable Functions" example
using existentials cited here last week [1].
Your comment about the type of Source and Sink being too general is
interesting. In general, you're asking for GADTs [2], though this
instance is simple enough you could possibly hack up a solution
without them.
Chris
[1] http://groups.google.com/group/fa.caml/msg/8f11bc7839aac98f
[2] http://www.haskell.org/haskellwiki/Generalised_algebraic_datatype
On Mon, Mar 24, 2008 at 5:56 PM, Dario Teixeira <darioteixeira@yahoo.com> wrote:
> 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/
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
next prev parent reply other threads:[~2008-03-24 22:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-24 21:56 Dario Teixeira
2008-03-24 22:17 ` [Caml-list] " Daniel Bünzli
2008-03-24 22:19 ` Christopher L Conway [this message]
2008-03-24 23:03 ` Jeremy Yallop
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=4a051d930803241519j36c2cc7cm7d3cb745acaa6af@mail.gmail.com \
--to=cconway@cs.nyu.edu \
--cc=caml-list@yquem.inria.fr \
--cc=darioteixeira@yahoo.com \
/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