From: Mike McClurg <mike.mcclurg@gmail.com>
To: Hongbo Zhang <bobzhang1988@gmail.com>, caml-list@inria.fr
Subject: [Caml-list] Re: Generating a module implementation from a module signature using camlp4
Date: Fri, 12 Oct 2012 22:01:07 +0100 [thread overview]
Message-ID: <CALru5wUoHcFwqnWy7Q1_B2LfiJPpTv2DPdz4V5rkUpUtYvupcA@mail.gmail.com> (raw)
In-Reply-To: <507871F9.5040605@gmail.com>
On Fri, Oct 12, 2012 at 8:39 PM, Hongbo Zhang <bobzhang1988@gmail.com> wrote:
> On 10/12/12 2:03 PM, Mike McClurg wrote:
>> On Fri, Oct 12, 2012 at 6:55 PM, Wojciech Meyer
>> <wojciech.meyer@googlemail.com> wrote:
>>>
>>> Hi Mike,
>>>
>>> You can explicitly pretty print the camlp4 quotations:
>>>
>>> let foo nm =
>>> <:str_item<module $uid:nm$ = struct let $lid:String.lowercase nm$ = ()
>>> end>>
>>>
>>> module OCamlPrinter = Camlp4.PreCast.Printers.OCaml;;
>>> OCamlPrinter.print_implem (foo "OK")
>>
>> Hi Wojciech,
>>
>> Thanks for that advice. I attempted something like this earlier, but
>> even with your printer module I get the following:
>>
>> Error: This expression has type AstFilters.Ast.str_item
>> but an expression was expected of type Camlp4.PreCast.Ast.str_item
>>
>> Is there any way to unify the modules AstFilters.Ast and
>> Camlp4.PreCast.Ast? In my earlier attempt I tried some module Foo =
>> Blah with module ... trickery, but I couldn't seem to unify the types
>> properly.
>
> They are actually the same, unfortunately the interface does not expose the
> equality, the ugly solution is to use
> Obj.magic
Hey, that works! I probably wouldn't have thought to use Obj.magic. I
think it's probably OCaml's goto statement. It's not that it should
never be used, but there are so few cases where it's appropriate that
we condition ourselves not to think about it. Well, at least I have.
> Another solution to your problem is to use map to traverse sig_item, but
> maintain a state in your object to collect them as str_items
Yes, that's basically what I want to do. I just needed a way to print
those str_items directly, because sig_item filters can only return
sig_items.
Thanks for the help Hongbo and Wojciech.
Mike
next prev parent reply other threads:[~2012-10-12 21:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 17:36 [Caml-list] " Mike McClurg
2012-10-12 17:55 ` Wojciech Meyer
2012-10-12 18:03 ` Mike McClurg
[not found] ` <507871F9.5040605@gmail.com>
2012-10-12 21:01 ` Mike McClurg [this message]
2012-10-13 13:06 ` [Caml-list] ocaml 3.12.1 and delimcc Christophe Raffalli
2012-10-13 14:38 ` Anthony Tavener
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=CALru5wUoHcFwqnWy7Q1_B2LfiJPpTv2DPdz4V5rkUpUtYvupcA@mail.gmail.com \
--to=mike.mcclurg@gmail.com \
--cc=bobzhang1988@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