From: Dario Teixeira <darioteixeira@yahoo.com>
To: Wolfgang Lux <wlux@uni-muenster.de>
Cc: Jeremy Yallop <jeremy.yallop@ed.ac.uk>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Troublesome nodes
Date: Sat, 12 Jul 2008 11:21:09 -0700 (PDT) [thread overview]
Message-ID: <761520.40658.qm@web54603.mail.re2.yahoo.com> (raw)
In-Reply-To: <F562803B-40A8-4914-8B20-03F8E9099308@uni-muenster.de>
Hi,
Thank you all for your help! I think we're almost there: with Wolfgang's
suggestion, the Node module complies with the original constraints, as the
code below shows: (the compiler complains -- as it should! -- when on the
last line I try to nest two link nodes directly)
module rec Node:
sig
type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ]
type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ]
type super_node_t = [ nonlink_node_t | link_node_t ]
val text: string -> nonlink_node_t
val bold: [< super_node_t] list -> nonlink_node_t
val see: string -> link_node_t
val mref: string -> nonlink_node_t list -> link_node_t
end =
struct
type nonlink_node_t = [ `Text of string | `Bold of Node.super_node_t list ]
type link_node_t = [ `See of string | `Mref of string * nonlink_node_t list ]
type super_node_t = [ nonlink_node_t | link_node_t ]
let text txt = `Text txt
let bold seq = `Bold (seq :> super_node_t list)
let see ref = `See ref
let mref ref seq = `Mref (ref, seq)
end
open Node
let foo1 = text "foo" (* valid *)
let foo2 = bold [text "foo"] (* valid *)
let foo3 = mref "ref" [text "foo"] (* valid *)
let foo4 = mref "ref" [see "ref"] (* invalid *)
Now, the icing on the cake would be the possibility to build a Node_to_Node
set of functions without code duplication. Ideally, I would like to do
something as follows:
module Node_to_Node =
struct
open Node
let rec convert_nonlink_node = function
| `Text txt -> Node.text txt
| `Bold seq -> Node.bold (List.map convert_super_node seq)
and convert_link_node = function
| `See ref -> Node.see ref
| `Mref (ref, seq) -> Node.mref ref (List.map convert_nonlink_node seq)
and convert_super_node node = match node with
| #nonlink_node_t -> (convert_nonlink_node node :> super_node_t)
| #link_node_t -> (convert_link_node node :> super_node_t)
end
But this fails on the last line:
Error: This expression has type
[< `Bold of 'a list & Node.super_node_t list | `Text of string ]
as 'a
but is here used with type
[< `Mref of string * 'a list | `See of string ]
These two variant types have no intersection
Do you see any way around it?
Thanks again for all your time and attention!
Cheers,
Dario
__________________________________________________________
Not happy with your email address?.
Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html
next prev parent reply other threads:[~2008-07-12 18:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-11 20:39 Dario Teixeira
2008-07-11 21:20 ` [Caml-list] " Jeremy Yallop
2008-07-12 12:37 ` Dario Teixeira
2008-07-12 13:25 ` Jacques Carette
2008-07-12 16:44 ` Wolfgang Lux
2008-07-12 18:21 ` Dario Teixeira [this message]
2008-07-12 18:27 ` Jeremy Yallop
2008-07-12 18:58 ` Jacques Carette
2008-07-11 23:11 ` Zheng Li
2008-07-13 14:32 ` [Caml-list] " Dario Teixeira
2008-07-13 17:39 ` Dario Teixeira
2008-07-13 21:10 ` Jon Harrop
2008-07-14 15:11 ` Dario Teixeira
2008-07-14 18:52 ` Dario Teixeira
2008-07-14 19:37 ` Jeremy Yallop
2008-07-16 21:22 ` Dario Teixeira
2008-07-17 0:43 ` Jacques Garrigue
2008-07-17 10:59 ` Jeremy Yallop
2008-07-18 2:34 ` Jacques Garrigue
2008-07-18 9:47 ` Jeremy Yallop
2008-07-18 13:02 ` Jacques Garrigue
2008-07-18 13:55 ` Jacques Garrigue
2008-07-19 2:15 ` Jacques Garrigue
2008-07-17 16:12 ` Dario Teixeira
2008-07-18 2:27 ` Jacques Garrigue
2008-07-18 13:09 ` Dario Teixeira
2008-07-18 17:36 ` Dario Teixeira
2008-07-19 2:23 ` Jacques Garrigue
2008-07-19 8:43 ` Dario Teixeira
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=761520.40658.qm@web54603.mail.re2.yahoo.com \
--to=darioteixeira@yahoo.com \
--cc=caml-list@yquem.inria.fr \
--cc=jeremy.yallop@ed.ac.uk \
--cc=wlux@uni-muenster.de \
/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