From: "Ömer Sinan Ağacan" <omeragacan@gmail.com>
To: Leo White <leo@lpw25.net>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Problems with printing MetaOCaml generated code
Date: Sun, 3 May 2015 11:50:45 -0400 [thread overview]
Message-ID: <CAMQQO3kfXZV6C1eSyFKe4+HwfK3MS0NaVZfuQOqkRvORjJ+6=A@mail.gmail.com> (raw)
In-Reply-To: <1430666669.231526.262065573.6E243323@webmail.messagingengine.com>
> Personally, I think it is best to avoid this auto-magic and just do your
> lifting by hand. The type-based auto-magic doesn't work with polymorphism,
> whilst the value-based auto-magic is not parametric.
Hm, I didn't know this was possible. I just tried and it seems to work really
well:
type stx =
| A
| B of stx
| C of (stx * stx)
let rec lift_stx (stx : stx) : stx code =
match stx with
| A -> .< A >.
| B stx' -> .< B .~ (lift_stx stx') >.
| C (stx1, stx2) -> .< C ( .~ (lift_stx stx1), .~ (lift_stx stx2) ) >.
let stx = C (C (C (A, A), C (A, A)), C (C (A, A), C (A, A))) in
print_code std_formatter .< .~ (lift_stx stx) >.;
So it seems like I finally have a workaround now, thanks!
The story of MetaOCaml code printing is still not completely clear to me, and
this workaround means lots of boilerplace, but at least I have a workaround now
and I can make progress.
2015-05-03 11:24 GMT-04:00 Leo White <leo@lpw25.net>:
>> I don't think this is true, as far as I can see MetaOCaml doesn't have open code
>> values that are only runnable in environments that bind free variables in the
>> code.
>>
>> # .<a>.;;
>> Error: Unbound value a
>> # let a = 1 in .<a>.;;
>> - : int code = .<1>.
>>
>> In this example `.<a>.` didn't mean a code that is just the variable `a`,
>> instead, `a` is lifted in code and code is now `.<1>.`.
>>
>> I think this automatic lifting is why MetaOCaml doesn't have explicit "lift"
>> operation like MetaML does: variables bound in the environment automatically
>> lifted, so no open code values are possible.
>
> It is true that MetaOCaml tries to auto-magically lift *some* things for you
> (e.g. ints), as in this example. If type information is available, then for known
> types it can produce a call to a function such as `Trx.lift_constant_int` to do the
> lifting. For other types it will examine the value at run-time and attempt to lift it.
> For example, if the value has a "string tag" then it can be represented by a string
> literal. If this fails then it will fall back to using true CSP -- which can be run but
> cannot be printed.
>
> Personally, I think it is best to avoid this auto-magic and just do your lifting by
> hand. The type-based auto-magic doesn't work with polymorphism, whilst the
> value-based auto-magic is not parametric.
>
> Regards,
>
> Leo
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
next prev parent reply other threads:[~2015-05-03 15:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 18:36 Ömer Sinan Ağacan
2015-04-30 19:52 ` Jacques Carette
2015-04-30 20:25 ` Ömer Sinan Ağacan
2015-04-30 20:57 ` Ömer Sinan Ağacan
2015-04-30 21:35 ` Jeremy Yallop
2015-05-01 11:21 ` oleg
2015-05-01 14:34 ` Ömer Sinan Ağacan
2015-05-01 16:16 ` Leo White
2015-05-01 16:41 ` Ömer Sinan Ağacan
2015-05-01 16:45 ` Leo White
2015-05-01 16:53 ` Ömer Sinan Ağacan
2015-05-02 18:45 ` Ömer Sinan Ağacan
2015-05-02 20:49 ` Jacques Carette
2015-05-03 1:56 ` Ömer Sinan Ağacan
2015-05-03 2:28 ` Jacques Carette
2015-05-03 3:19 ` Ömer Sinan Ağacan
2015-05-03 8:40 ` Gabriel Scherer
2015-05-03 14:28 ` Ömer Sinan Ağacan
2015-05-03 15:24 ` Leo White
2015-05-03 15:50 ` Ömer Sinan Ağacan [this message]
2015-05-06 9:50 ` oleg
2015-05-06 15:58 ` Jeremy Yallop
2015-05-06 16:45 ` Yotam Barnoy
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='CAMQQO3kfXZV6C1eSyFKe4+HwfK3MS0NaVZfuQOqkRvORjJ+6=A@mail.gmail.com' \
--to=omeragacan@gmail.com \
--cc=caml-list@inria.fr \
--cc=leo@lpw25.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