From: Ashish Agarwal <agarwal1975@gmail.com>
To: Jeremy Yallop <yallop@gmail.com>
Cc: Caml List <caml-list@inria.fr>,
Eric Jaeger <eric.jaeger@ssi.gouv.fr>,
Philippe Wang <mail@philippewang.info>
Subject: Re: [Caml-list] Function returning recursive lists
Date: Thu, 20 Dec 2012 10:24:08 -0500 [thread overview]
Message-ID: <CAMu2m2JwxXo-4ujf0A1LbPo3YOCmvUd+Cab91ekWD5m_A5KMHw@mail.gmail.com> (raw)
In-Reply-To: <CAAxsn=EU9vTW+ozKTTCKT7vszuLKV=ERJCdK5S7d2pMyspgYaw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1706 bytes --]
It would be nice to have metaocaml as one of the available compilers in
opam. Anyone thinking of doing that?
On Wed, Dec 19, 2012 at 6:50 PM, Jeremy Yallop <yallop@gmail.com> wrote:
> On 19 December 2012 22:23, Philippe Wang <mail@philippewang.info> wrote:
> > I have a (somehow silly) answer to your question:
> >
> > let gen_make_circ n =
> > Printf.printf "let make_circ = function [] -> []\n";
>
> That's an interesting idea, Philippe. Here's an approach along the
> same lines using MetaOCaml.
>
> let rec docycle l =
> .!(.< let rec s =
> .~(let rec loop = function
> | [] -> .< s >.
> | x :: xs -> .< x :: .~(loop xs) >.
> in loop l)
> in s >.)
>
> The essential idea is the same as in your code: dynamically generating
> a suitable 'let rec' expression. However, MetaOCaml also helpfully
> guarantees that the generated code is well-formed and well-typed, and
> makes it possible to compile and run the generated code without
> leaving the language.
>
> Here's the code in action:
>
> # docycle;;
> - : 'a list -> 'a list = <fun>
> # docycle [1;2;3];;
> - : int list = [1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2; 3; 1; 2;
> 3; 1; ...]
> # docycle [1;2;3;4;5];;
> - : int list = [1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2; 3; 4; 5; 1; 2;
> 3; 4; ...]
>
> (For the sake of simplicity I haven't handled the case where the input
> list is empty, but that's not difficult to do.)
>
> --
> 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
>
[-- Attachment #2: Type: text/html, Size: 2520 bytes --]
next prev parent reply other threads:[~2012-12-20 15:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <50d02b62.827bc20a.6f6e.65b8SMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-19 22:23 ` Philippe Wang
2012-12-19 23:50 ` Jeremy Yallop
2012-12-20 15:24 ` Ashish Agarwal [this message]
[not found] <50d02b65.6c4cb40a.66ab.4256SMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-18 11:21 ` Julien Blond
2012-12-18 13:13 ` Eric Jaeger
[not found] ` <50d06c18.0f5cc20a.16d8.ffff8b8cSMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-19 16:45 ` Lukasz Stafiniak
[not found] <50d02b72.7155c20a.1dbf.4e2fSMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-18 9:35 ` Gabriel Scherer
2012-12-18 8:37 Eric Jaeger
2012-12-21 19:55 ` Peter Frey
2012-12-22 18:10 ` Philippe Wang
[not found] ` <50D59147.3000201@ssi.gouv.fr>
2012-12-28 1:41 ` Peter Frey
2012-12-28 9:37 ` Arkady Andrukonis
2012-12-28 12:21 ` Philippe Wang
2012-12-28 12:30 ` Philippe Wang
2012-12-28 15:22 ` Didier Cassirame
2013-01-04 0:45 ` Francois Berenger
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=CAMu2m2JwxXo-4ujf0A1LbPo3YOCmvUd+Cab91ekWD5m_A5KMHw@mail.gmail.com \
--to=agarwal1975@gmail.com \
--cc=caml-list@inria.fr \
--cc=eric.jaeger@ssi.gouv.fr \
--cc=mail@philippewang.info \
--cc=yallop@gmail.com \
/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