From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Private types in 3.11, again
Date: Tue, 20 Jan 2009 08:33:53 -0800 (PST) [thread overview]
Message-ID: <865755.99476.qm@web111508.mail.gq1.yahoo.com> (raw)
In-Reply-To: <597161.6065.qm@web111501.mail.gq1.yahoo.com>
Hi again,
I ditched the regular variants in favour of polymorphic variants, hoping
the coercion trick described by Jacques Garrigue would help [1]. I've also
simplified the formulation as much as possible. Anyway, I'm still stuck
with the same problem: while function 'sprint' works alright inside the
Node module, its clone 'sprint2' fails to compile when placed outside.
Is this a case where no amount of explicit annotations and coercions will
work or am I missing something obvious?
Thanks in advance!
Regards,
Dario Teixeira
[1] http://groups.google.com/group/fa.caml/msg/855011402f1ca1b5
module Node:
sig
type elem_t = [ `Text of string | `Bold of elem_t list ]
type +'a t = private elem_t
val text: string -> [> `Basic ] t
val bold: 'a t list -> [> `Complex ] t
val sprint: 'a t -> string
end =
struct
type elem_t = [ `Text of string | `Bold of elem_t list ]
type +'a t = elem_t
let text str = `Text str
let bold seq = `Bold seq
let rec sprint = function
| `Text str -> Printf.sprintf "(Text %s)" str
| `Bold seq -> Printf.sprintf "(Bold %s)" (List.fold_left (^) "" (List.map sprint seq))
end
module Foobar:
sig
val sprint2: 'a Node.t -> string
end =
struct
let rec sprint2 node = match (node : _ Node.t :> [> ]) with
| `Text str -> Printf.sprintf "(Text %s)" str
| `Bold seq -> Printf.sprintf "(Bold %s)" (List.fold_left (^) "" (List.map sprint2 (seq : _ Node.t list :> [>] list)))
end
next prev parent reply other threads:[~2009-01-20 16:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-15 17:31 Dario Teixeira
2009-01-19 15:09 ` [Caml-list] " Dario Teixeira
2009-01-20 16:33 ` Dario Teixeira [this message]
2009-01-20 17:29 ` Jacques Carette
2009-01-20 17:48 ` Dario Teixeira
2009-01-21 10:48 ` Jacques Garrigue
2009-01-21 10:38 ` Jacques Garrigue
2009-01-21 13:22 ` Jacques Garrigue
2009-01-21 19:11 ` Dario Teixeira
2009-01-21 20:17 ` Gabriel Kerneis
2009-01-21 21:52 ` GADTs in Ocaml (was: Private types in 3.11, again) Dario Teixeira
2009-01-22 1:36 ` [Caml-list] Private types in 3.11, again Jacques Garrigue
2009-01-26 15:13 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=865755.99476.qm@web111508.mail.gq1.yahoo.com \
--to=darioteixeira@yahoo.com \
--cc=caml-list@yquem.inria.fr \
/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