caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Julien Signoles <julien.signoles@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Converting "fun ... (type t) ..." into a caml < 3.12 code
Date: Wed, 26 Jan 2011 17:30:25 +0100	[thread overview]
Message-ID: <AANLkTimX5y-RKkToP65E1GBfuc1ktz2r6gH12eigTWjJ@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinyQn4L0C8hHHXJP20upzi++2oKU6RC-2ZTEjDA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]

Sorry, forgot the list...

---------- Forwarded message ----------
From: Julien Signoles <julien.signoles@gmail.com>
Date: 2011/1/26
Subject: Re: [Caml-list] Converting "fun ... (type t) ..." into a caml <
3.12 code
To: Stefan Holdermans <stefan@vectorfabrics.com>




2011/1/26 Stefan Holdermans <stefan@vectorfabrics.com>

 > How to convert the following ocaml 3.12 code into a typable ocaml < 3.12
> code?
>
> Coincidentally, earlier today, I ran into a situation not that different
> from the one you describe. I haven't come up with a satisfying solution yet.
>
> > I have a solution using Obj. Is it possible without Obj?
>
> Are you willing to share this solution?
>

====
let g (x:'a) =

  let module S =
    Set.Make(struct
      type t = Obj.t

      let compare = Pervasives.compare
      let equal = ( = )
    end)
  in
  (Obj.magic (S.elements (S.singleton (Obj.repr x))) : 'a list)
(* less efficient but using Obj.obj instead of Obj.magic: *)
(*  List.rev (S.fold (fun o acc -> (Obj.obj o:'a) :: acc) (S.singleton
(Obj.repr x)) []) *)
====

Note that:
1) I'm pretty sure someone who initials are XL will be unhappy with such a
solution
2) For a real-world application [*], I prefer to leave a known bug instead
of fixing it using such a solution... And either waiting for a solution
without Obj or waiting for a future day where our software will require
ocaml 3.12

--
Julien

[*] Frama-C (http://frama-c.com)

[-- Attachment #2: Type: text/html, Size: 2222 bytes --]

  parent reply	other threads:[~2011-01-26 16:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26 12:58 Julien Signoles
2011-01-26 15:17 ` Stefan Holdermans
     [not found]   ` <AANLkTinyQn4L0C8hHHXJP20upzi++2oKU6RC-2ZTEjDA@mail.gmail.com>
2011-01-26 16:30     ` Julien Signoles [this message]
2011-01-26 16:55 ` Jeremy Yallop
2011-01-27 14:18   ` Julien Signoles

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=AANLkTimX5y-RKkToP65E1GBfuc1ktz2r6gH12eigTWjJ@mail.gmail.com \
    --to=julien.signoles@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).