caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Hars <hars@bik-gmbh.de>
To: caml-list@inria.fr
Subject: [Caml-list] Getting rid of impossible polymorphic variant tags from infered types
Date: Mon, 01 Mar 2004 16:09:02 +0100	[thread overview]
Message-ID: <4043520E.2040802@bik-gmbh.de> (raw)

If I write a function to filter out all occurences of values of a specific 
polymorphic variant tag from a list, ocaml infers a return type for this 
function of any type that may contain the tag I have just removed:

# let f l = List.filter (function `Fnord -> false | _ -> true) l;;
val f : ([> `Fnord] as 'a) list -> 'a list = <fun>

While I unterstand why this type is infered, it is nonetheless wrong, it should 
be something like [> 'a \ `Fnord ] list (inventing notation on the fly).
Is there some decent way to tell the compiler that I know more about this 
function than the type checker does?

The following should be safe, but doesn't strike me as especially elegant and 
makes the type more restrictive than I'd like it to be:

type foo = [ `Foo | `Bar | `Fnord ]
type foo_flat = [ `Foo | `Bar ]

let f' l =
   let f_r (v: foo) (init: foo_flat list) =
     match v with
     | `Fnord -> init
     | _ -> Obj.magic v :: init
   in
   List.fold_right f_r l []

Yours, Florian.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2004-03-01 15:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-01 15:09 Florian Hars [this message]
2004-03-01 16:35 ` Claudio Sacerdoti Coen
2004-03-03 10:27   ` Florian Hars
2004-03-03 10:40     ` Claudio Sacerdoti Coen

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=4043520E.2040802@bik-gmbh.de \
    --to=hars@bik-gmbh.de \
    --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).