From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@etu.upmc.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] getting the type of a polymorphic data ?
Date: Thu, 12 Aug 2004 14:47:07 +0200 (DST) [thread overview]
Message-ID: <Pine.A41.4.44.0408121435230.557174-100000@ibm1> (raw)
In-Reply-To: <20040812143443.2aba80c1@babasse>
Bonjour
[Je poste la réponse à une question qui m'a été posée en dehors de la
liste car mes explications semblent ne pas avoir été claires]
> mal compris ton problème -- pourquoi ne pas définir un type du genre :
>
> type number = Int of int | Float of float
>
> et faire un matching qui ressemblerait à
>
> let x' = match x with
> | Int x -> IntSet.from_poly x
> | Float x -> FloatIntervalSet.from_poly x
Parce que ce n'est pas moi qui définit x. En fait (voir message
initial) x est un ensemble de type polymorphe car l'utilisateur est
supposé pouvoir y mettre ses propres types.
Voici la situation que je veux _éviter_ (exemple tiré de FaCiLe -
Pascal Brisset et Nicolas Barnier)
let
yellow = 0 and
blue = 1 and
green = 2
in
let x = IntDomain.from_list [0; 1; 2]
A la place je veux
type color = Yellow | Blue | Green
let x = Domain.from_list [Yellow ; Blue; Green]
Mais il faut que la partie interne de la librairie, elle, manipule un
ensemble d'entiers (pour des questions de performance puisqu'il s'agit
d'optimisation combinatoire).
D'où l'idée simple
let x = Domain.from_list [(hash Yellow) ; (hash Blue) ; (hash Green)]
ou encore
let x = Domain.from_list_hashed [ Yellow ; Blue ; Green]
Mais pour que cette optimisation soit correcte, il faut que hash x =
hash y => x = y, d'où ma question.
Autre précision, ce n'est pas grave si un type est isomorphe à un
entier mais le compilateur ne le voit pas par exemple
type x = A of int
Obj.is_int (A 1)
# false
Diego Olivier
-------------------
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
next parent reply other threads:[~2004-08-12 12:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20040812143443.2aba80c1@babasse>
2004-08-12 12:47 ` Diego Olivier Fernandez Pons [this message]
2004-08-12 13:11 ` [Caml-list] Compiling on windows (mingw) Daan Leijen
2004-08-12 13:22 ` Xavier Leroy
2004-08-12 13:35 ` Daan Leijen
2004-08-12 18:18 [Caml-list] getting the type of a polymorphic data ? Jean-Baptiste Rouquier
2004-08-13 8:15 ` Diego Olivier Fernandez Pons
2004-08-13 8:59 ` Diego Olivier Fernandez Pons
[not found] <Pine.A41.4.44.0408121350120.557174-100000@ibm1>
2004-08-12 12:09 ` Diego Olivier Fernandez Pons
2004-08-12 13:38 ` Damien Doligez
2004-08-12 13:57 ` Diego Olivier Fernandez Pons
2004-08-12 14:13 ` Marcin 'Qrczak' Kowalczyk
2004-08-12 14:26 ` Diego Olivier Fernandez Pons
-- strict thread matches above, loose matches on Subject: below --
2004-08-06 15:05 Diego Olivier Fernandez Pons
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=Pine.A41.4.44.0408121435230.557174-100000@ibm1 \
--to=diego.fernandez_pons@etu.upmc.fr \
--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