caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* polymorphic variants (2) + magic
@ 2000-06-09  9:15 David Chemouil
  2000-06-09  8:57 ` Obj.magic David Chemouil
  2000-06-12  8:27 ` polymorphic variants (2) + magic Jacques Garrigue
  0 siblings, 2 replies; 6+ messages in thread
From: David Chemouil @ 2000-06-09  9:15 UTC (permalink / raw)
  To: caml-list



Considering my two previous posts ("polymorphic variants" and
"Obj.magic"), I'd like to show how I had to merge them to have my
application work.

Indeed, I don't know yet completely the type 'argument', but I already
know some of its constructors. Then I use polymorphic constructors when
I need them and, when I'm able to do it, I will generate the 'argument'
type. 

The problem is that there are already functions which manipulate the
'argument' type. So, if I try to use them on an already known
polymorphic constructor, it doesn't work, because the constructor is not
known to belong to 'argument', as 'argument' isn't defined. 

My problem is then to be able to apply a function, of which the domain
is a yet undefined type, to a polymorphic constructor. My idea was to
have my already known polymorphic constructors considered as weak type
variables. Here is a simple example of the situation (I consider `A as
an already known constructor):

# type argument;;
type argument
# let id : argument -> argument = function x -> x;;
val id : argument -> argument = <fun>
# let x = `A;;
val x : [> `A] = `A
# let y = ! (ref `A);;
val y : _[> `A] = `A
# let z = Obj.magic `A;;
val z : '_a = <poly>
# id x;;
Characters 3-4:
This expression has type [> `A] but is here used with type argument
# id y;;
Characters 3-4:
This expression has type [> `A] but is here used with type argument
# id z;;
- : argument = <abstr>
# z;;
- : argument = <abstr>

As the example shows, the only solution for me is to use Obj.magic. Then
I'm sure everything will be well-typed. But is it completely correct to
do like this? 


-- 
David Chemouil [mailto:chemouil@enseeiht.fr] [mobile: 06 84 16 26 65]

Laboratoire d'informatique et de mathématiques appliquées (IRIT-INPT)

"Je vous ai fait trop faibles pour sortir du gouffre, parce que 
 je vous ai fait assez forts pour n'y point tomber" -- Rousseau




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-06-13 16:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-09  9:15 polymorphic variants (2) + magic David Chemouil
2000-06-09  8:57 ` Obj.magic David Chemouil
2000-06-12  4:15   ` polymorphic variants (2) + magic Ken Wakita
2000-06-12 16:20     ` Obj.magic Jean-Christophe Filliatre
2000-06-12  4:33   ` Obj.magic Daniel de Rauglaudre
2000-06-12  8:27 ` polymorphic variants (2) + magic Jacques Garrigue

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).