caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: "Matej Košík" <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] concerning using of `deriving' syntactic plugin
Date: Wed, 7 Mar 2012 13:31:32 +0100	[thread overview]
Message-ID: <CAPFanBE=DrYN8WZxVs8eB2DK8KhLE-uAzegSM8FVTz7HMydwig@mail.gmail.com> (raw)
In-Reply-To: <4F574B3C.5000207@gmail.com>

You can inject the definition you want in the following way:

  module Meths = struct
    include Meths
    module Show_t = ...
  end

  type value_kind = ...
  deriving (Show)

This works because deriving, being a Camlp4 extension, does not refer
to "the" module Meths, but any module Meths that is in scope at the
place of expansion. This could be seen as a defect of hygiene (indeed
that makes camlp4 macro non-hygienic according to the Scheme notion of
hygiene) but is also a feature, rather than a bug, of the syntactic
macro system; because as a macro-writer you can give flexibility to
the user by specifying the free variables you rely on.

On Wed, Mar 7, 2012 at 12:49 PM, Matej Košík
<5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> Hi,
>
> I would like to print out the response of a modified Ocaml's typechecker
> to various inputs.
>
> One way to do it would be to write a pretty-printer by hand.
>
> Before I do that, I would like to apply "deriving" machinery:
> http://code.google.com/p/deriving/wiki/Introduction
> to this (chore) job.
>
> In some cases I do not know what to do.
>
> E.g., file "types/types.mli" contains the following definition:
>
>  and value_kind =
>      Val_reg
>    | Val_prim of Primitive.description
>    | Val_ivar of mutable_flag * string
>    | Val_self of
>        (Ident.t * type_expr) Meths.t ref *
>        (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t ref *
>      string * type_expr
>    | Val_anc of (string * Ident.t) list * string
>    | Val_unbound
>
> If I add
>
>  deriving (Show)
>
> at the end of the above definition, I get an error:
>
>  Error: Unbound module Meths.Show_t
>
> That is expected but I am not sure what to do. That is, I am not sure
> what is the official way to "deriving"-sify the "Meth" module which
> defined in the following way:
>
>  module Meths = Map.Make(OrderedString)
>
> without the need to modify files "map.ml{i,}".
>
> Is something like that possible?
>
> Thank you very much in advance for any help.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-03-07 12:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-07 11:49 Matej Košík
2012-03-07 12:31 ` Gabriel Scherer [this message]
2012-03-07 16:44   ` Matej Košík
2012-03-07 17:06     ` Jérémie Dimino
2012-03-07 12:34 ` Yaron Minsky
2012-03-07 16:44   ` Matej Košík
2012-03-07 17:10     ` Markus Mottl
2012-03-07 17:28       ` Matej Košík
2012-03-07 20:47         ` Till Varoquaux
2012-03-08  2:49         ` Markus Mottl

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='CAPFanBE=DrYN8WZxVs8eB2DK8KhLE-uAzegSM8FVTz7HMydwig@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=5764c029b688c1c0d24a2e97cd764f@gmail.com \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).