From: Jacques Carette <carette@mcmaster.ca>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Troublesome nodes
Date: Sat, 12 Jul 2008 09:25:06 -0400 [thread overview]
Message-ID: <4878B0B2.4020501@mcmaster.ca> (raw)
In-Reply-To: <197205.74716.qm@web54603.mail.re2.yahoo.com>
The ingenious use of a recursive module signature seems to be the source
of the problem here. If one defines 'bar' inside the module Node, it
works fine [but is clearly useless].
What surprises me is that the code (below) also gives the exact same
error. In other contexts, I have managed to get such annotations (see
the definition of the bold function) to 'work', but not here. I am
quite puzzled by this, so if you do get an answer to your question
offl-ist, I would appreciate if you could forward it on.
Jacques
PS: because I am actually using metaocaml for other projects, I am using
ocaml 3.09 for my tests, so it is possible that something is different
in 3.10.
module Node :
sig
type nonlink_node_t
type link_node_t
type super_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 'a p1 = [ `Text of string | `Bold of 'a list ]
type 'a p2 = [ `See of string | `Mref of string * 'a p1 list ]
type 'a p3 = [ 'a p1 | 'a p2 ]
type super_node_t = super_node_t p3
type nonlink_node_t = super_node_t p1
type link_node_t = super_node_t p2
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;;
Dario Teixeira wrote:
> Hi,
>
> Thanks Jeremy, that's quite ingenious. However, I've hit a problem in the
> definition of the constructor functions (the full code + compiler error
> is below). Now, I know that nonlink_node_t is a subset of super_node_t,
> and therefore any variant valid for nonlink_node_t is also acceptable for
> super_node_t. But how do I tell this to the compiler? (Note that having
> users of the module manually casting types with :> is something I would
> rather avoid).
>
> Thanks again,
> Dario
>
>
> 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
> let see ref = `See ref
> let mref ref seq = `Mref (ref, seq)
> end
>
> open Node
> let foo = text "foo"
> let bar = bold [text "bar"]
>
>
> Error: This expression has type Node.nonlink_node_t
> but is here used with type Node.super_node_t
> The first variant type does not allow tag(s) `Mref, `See
>
>
>
>
> __________________________________________________________
> 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
>
> _______________________________________________
> 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-07-12 13:25 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 [this message]
2008-07-12 16:44 ` Wolfgang Lux
2008-07-12 18:21 ` Dario Teixeira
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=4878B0B2.4020501@mcmaster.ca \
--to=carette@mcmaster.ca \
--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