caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Boris Yakobowski <boris@yakobowski.org>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: Damien Guichard <alphablock@orange.fr>,
	caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] obj.magic for polymorphic record fields
Date: Mon, 21 Dec 2009 15:00:19 +0100	[thread overview]
Message-ID: <76c7f53f0912210600y91c9b76ib07d130cf7cf251f@mail.gmail.com> (raw)
In-Reply-To: <87zl5cmof9.fsf@frosties.localdomain>

On Mon, Dec 21, 2009 at 2:44 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
>> However it issues a warning so i acknowledge it's less elegant.
>
> Which I don't quite understand.

The warning is based on the results of the type inference algorithm.
You're not supposed to find values of type 'a. 'a "in the wild", yet
(Obj.magic a) has this type. Thus the Ocaml compiler deduces that
you're doing something wrong: your function never returns, it does not
use its arguments, etc. Here, using Obj.magic breaks the crystal ball
of the compiler, and the warning is incorrect.

There is an easy way to silence the warning though:

let baz = {bar = fun x -> (Obj.magic a : _ -> _) x}

(but not let baz = {bar = fun x -> (Obj.magic a : 'a -> 'a) x} for
ugly reasons...)

You are however quite correct. Using Obj.magic in this particular case
seems quite wrong.

-- 
Boris


  reply	other threads:[~2009-12-21 14:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-20 18:45 Re[2]: " Damien Guichard
2009-12-21 13:44 ` Goswin von Brederlow
2009-12-21 14:00   ` Boris Yakobowski [this message]
2009-12-21 16:05     ` Jacques Le Normand
2009-12-22 13:35     ` Goswin von Brederlow
2009-12-22 21:49       ` Boris Yakobowski
2009-12-24 12:10         ` Goswin von Brederlow
  -- strict thread matches above, loose matches on Subject: below --
2009-12-20 17:44 Jacques Le Normand
2009-12-20 18:17 ` [Caml-list] " Nicolas Pouillard

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=76c7f53f0912210600y91c9b76ib07d130cf7cf251f@mail.gmail.com \
    --to=boris@yakobowski.org \
    --cc=alphablock@orange.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=goswin-v-b@web.de \
    /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).