From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@yquem.inria.fr
Cc: Jon Harrop <jon@ffconsultancy.com>
Subject: Re: [Caml-list] Troublesome nodes
Date: Mon, 14 Jul 2008 11:52:49 -0700 (PDT) [thread overview]
Message-ID: <831.74975.qm@web54604.mail.re2.yahoo.com> (raw)
In-Reply-To: <790934.91073.qm@web54606.mail.re2.yahoo.com>
Hi,
After some trial and error in the top-level, I think I got the hang of the
'constraint' declaration (is there other documentation for it besides the
couple of lines in the Reference Manual?). Note that besides the already
discussed link/nonlink distinction between nodes, there is now also an
orthogonal distinction between basic/complex nodes (all nodes except for
Mref are basic; any document that uses Mref thus becomes "contaminated"
and cannot use basic-only functions; the inverse, however, is not true).
I took advantage of Jon's suggestion of boxing all return types into a
single Node.t to implement this latter distinction using phantom types
(is there even an alternative technique?).
Now, the code below seems correct, and running "ocamlc -i node.ml" produces
the type signatures you would expect, and without error messages. However,
running "ocamlc -c node.ml" fails with a "The type of this expression contains
type variables that cannot be generalized" error on the declaration of foo3.
Moreover, if you comment out the top-level declarations and try to compile
only the module declaration, you will also get different results whether you
run "ocamlc -i" or "ocamlc -c". The former displays the module's signature
as expected, but the latter produces this error message:
Type declarations do not match:
type ('a, 'b) t = ('a, 'b) Node.t constraint 'a = [< super_node_t ]
is not included in
type ('a, 'b) t = private 'a constraint 'a = [< super_node_t ]
I find this behaviour a bit odd. What is going on?
Best regards,
Dario Teixeira
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 ]
type ('a, 'b) t = private 'a constraint 'a = [< super_node_t ]
val text: string -> ([> nonlink_node_t], [> `Basic]) t
val bold: ([< super_node_t], 'a) t list -> ([> nonlink_node_t], 'a) t
val see: string -> ([> link_node_t], [> `Basic]) t
val mref: string -> (nonlink_node_t, 'a) t list -> ([> link_node_t], [> `Complex]) t
val make_basic: ([< super_node_t], [< `Basic]) t -> (super_node_t, [`Basic]) t
val make_complex: ([< super_node_t], [< `Basic | `Complex]) t -> (super_node_t, [`Complex]) 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 ]
type ('a, 'b) t = 'a constraint 'a = [< super_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)
let make_basic n = (n :> (super_node_t, [`Basic]) t)
let make_complex n = (n :> (super_node_t, [`Complex]) t)
end
open Node
let foo1 = text "ola"
let foo2 = bold [text "ola"]
let foo3 = mref "ref" [foo1; foo2]
let basic1 = make_basic foo1
let basic2 = make_basic foo2
let complex1 = make_complex foo1
let complex2 = make_complex foo2
let complex3 = make_complex foo3
__________________________________________________________
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-14 18:52 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
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 [this message]
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=831.74975.qm@web54604.mail.re2.yahoo.com \
--to=darioteixeira@yahoo.com \
--cc=caml-list@yquem.inria.fr \
--cc=jon@ffconsultancy.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