From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 6A6977EDE3 for ; Fri, 12 Oct 2012 23:01:20 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of mike.mcclurg@gmail.com) identity=pra; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="mike.mcclurg@gmail.com"; x-sender="mike.mcclurg@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of mike.mcclurg@gmail.com designates 209.85.220.54 as permitted sender) identity=mailfrom; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="mike.mcclurg@gmail.com"; x-sender="mike.mcclurg@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pa0-f54.google.com) identity=helo; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="mike.mcclurg@gmail.com"; x-sender="postmaster@mail-pa0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlgDAH+EeFDRVdw2lGdsb2JhbABFv2AIIwEBAQEJCQsJEimCIAEBAQMBEgIsARseAwELBgULAwouIQEBEQEFARwGARIIEweHTwEDCQacaQkDjCaCdoRvChknDVmIdQEFDIpgZoY9A5QYgVWLI4MsFimEEA X-IronPort-AV: E=Sophos;i="4.80,578,1344204000"; d="scan'208";a="158884565" Received: from mail-pa0-f54.google.com ([209.85.220.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 12 Oct 2012 23:01:09 +0200 Received: by mail-pa0-f54.google.com with SMTP id bi1so3734814pad.27 for ; Fri, 12 Oct 2012 14:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Mw8iy6+K5bMP5XZM8Y0pofOgg8o8aI3BsqnXAhDMO/U=; b=QP74Kvg0+q7I1a6tIxs4lxi/Mf71oenEiGnXOQjzTeQ7bmNu+syyRXVUhzL1OS1dC+ ujwJnSFVEbPeWu8ITZzBSFef/Oal1zC8gGoSqhieIERCIEvV2HmzoQftKP0vKGPIfifW faWhzQ38eO8MNsgcRrNICgf9DHnf5iyuQGSCwu5iYLCp6lI7YwADkpPCvyUnNO9IXszI LHfqcaDF2lf4c4wTGGJhYta7Sc/VnH5BuP6AbUzFQChPLgt4q5cGFvQXlF5ZsUHejY5i 9e2AYU0+iaxPQPeJaRpqnteha7JigdXbqVTMY0D1wE6VSMezWrqER5TChRbYPaRGODWU kTsA== MIME-Version: 1.0 Received: by 10.68.233.196 with SMTP id ty4mr16695677pbc.23.1350075667402; Fri, 12 Oct 2012 14:01:07 -0700 (PDT) Received: by 10.68.124.101 with HTTP; Fri, 12 Oct 2012 14:01:07 -0700 (PDT) In-Reply-To: <507871F9.5040605@gmail.com> References: <507871F9.5040605@gmail.com> Date: Fri, 12 Oct 2012 22:01:07 +0100 Message-ID: From: Mike McClurg To: Hongbo Zhang , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] Re: Generating a module implementation from a module signature using camlp4 On Fri, Oct 12, 2012 at 8:39 PM, Hongbo Zhang wrote: > On 10/12/12 2:03 PM, Mike McClurg wrote: >> On Fri, Oct 12, 2012 at 6:55 PM, Wojciech Meyer >> wrote: >>> >>> Hi Mike, >>> >>> You can explicitly pretty print the camlp4 quotations: >>> >>> let foo nm = >>> <:str_item>> 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