polymorphic variants (2) + magic

From: David Chemouil (David.Chemouil@enseeiht.fr)
Date: Fri Jun 09 2000 - 11:15:58 MET DST

  • Next message: Joshua D. Guttman: "OCaml book"

    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



    This archive was generated by hypermail 2b29 : Fri Jun 09 2000 - 19:46:51 MET DST