Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-08-12 (15:21)
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@e...>
Subject: Re: [Caml-list] Managing a polymorphic environment

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 Archives:
Bug reports: FAQ:
Beginner's list: