Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Managing a polymorphic environment
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@e...>
Subject: Re: [Caml-list] Managing a polymorphic environment
    Bonjour,

You are breaking type transparency (or have I misunderstood ?).
Otherwise you can always encapsulate your types (in a module) and
generate a unique integer (with a reference incremented every time you
call the generating function)

> let x = new foo_int 10 "the number of elements in the knapsack"
> Env.add x (*x is coerced to foo, we forget it's an int*)
> let c = new foo_float "the total cost of the knapsack"
> Env.add c
>
> x#print
> c#print

let say Env is a set with hashed keys
Env.add : 'a -> unit

type color = Blue | White | Red

let print_color = function x ->
 let message = Env.get_string (Hashtbl.hash x) in
   match x with
    | Blue -> print_string message ^ "blue"
    | etc.

# print_color;;
- color -> unit = <fun>

let x = Blue
Env.add x
print_color x

-- Here the problem is 'let' --


        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