From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Sylvain Le Gall <sylvain@le-gall.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Type constraint to explain that a polymorphic variants is included into another
Date: Sat, 9 Oct 2010 05:09:23 +0900 [thread overview]
Message-ID: <CE9DC29C-F580-4703-9C6C-87CEF7994455@gmail.com> (raw)
In-Reply-To: <slrniauk9n.fmh.sylvain@gallu.homelinux.org>
On 2010/10/09, at 2:13, Sylvain Le Gall wrote:
> Hello all,
>
> I would like to build an interface for plugins that allow to extract at the
> same time a very specific data for a plugin family and to extract
> general help for plugins.
>
> Here is an example:
[...]
> This code doesn't compile because I see no way to explain that F.kind is
> included into plugin_kind.
I'm not sure of what you are trying to do, but private rows where introduced
with this goal in mind.
The idea is to change the abstract definition of kind in PLUGIN_FAMILY to
type kind = private [< plugin_kind]
meaning that kind can be instantiated to any subset of plugin_kind.
You can then use subtyping to convert from kind to plugin_kind.
Here is a typable version of your code.
Note that I had to do a few other changes to make the types match.
Jacques
(** All the plugins I want to manage *)
type plugin_kind = [`Build | `Install]
(** Generic plugin *)
type 'a plugin = 'a * string
(** Help data for all plugin *)
module MapPlugin =
Map.Make
(struct
type t = plugin_kind plugin
let compare = compare
end)
let all_help: string MapPlugin.t ref =
ref MapPlugin.empty
let help plg =
MapPlugin.find plg !all_help
(** Functor to build function related to one type of plugin *)
module type PLUGIN_FAMILY =
sig
type act
type kind = private [< plugin_kind]
val kind_default: kind
end
module Make (F: PLUGIN_FAMILY) =
struct
module MapPluginSelf =
Map.Make
(struct
type t = F.kind plugin
let compare = compare
end)
let all_act: F.act MapPluginSelf.t ref =
ref MapPluginSelf.empty
let act (plg : F.kind plugin) =
MapPluginSelf.find plg !all_act
let create name help act =
let id =
F.kind_default, name
in
all_help := MapPlugin.add (id :> plugin_kind * _) help !all_help;
all_act := MapPluginSelf.add id act !all_act;
id
end
(** Functions for build plugins *)
module Build =
Make
(struct
type act = unit -> unit
type kind = [`Build]
let kind_default = `Build
end)
(** Functions for install plugins *)
module Install =
Make
(struct
type act = string list -> unit
type kind = [`Install]
let kind_default = `Install
end)
type package =
{
name: string;
plugin_build: [`Build] plugin;
plugin_install: [`Install] plugin;
}
let run pkg =
prerr_endline (help (pkg.plugin_build :> MapPlugin.key));
prerr_endline (help (pkg.plugin_install :> MapPlugin.key));
(Build.act pkg.plugin_build) ();
Install.act pkg.plugin_install []
next prev parent reply other threads:[~2010-10-08 20:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-08 17:13 Sylvain Le Gall
2010-10-08 18:13 ` [Caml-list] " Jake Donham
2010-10-08 22:10 ` Sylvain Le Gall
2010-10-08 20:09 ` Jacques Garrigue [this message]
2010-10-11 8:49 ` Sylvain Le Gall
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=CE9DC29C-F580-4703-9C6C-87CEF7994455@gmail.com \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=sylvain@le-gall.net \
/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;
as well as URLs for NNTP newsgroup(s).