Browse thread
Re: [Caml-list] getting the type of a polymorphic data ?
-
Jean-Baptiste Rouquier
- Diego Olivier Fernandez Pons
- Diego Olivier Fernandez Pons
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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] getting the type of a polymorphic data ? |
Bonjour,
> # type 'a result = 'a * string;;
> # let new_result (a:'a) description = ((a,description) : 'a result);;
> val new_result : 'a -> string -> 'a result = <fun>
> # let print_int ((a,d): int result) = Printf.printf "%s is %d\n%!" d a;;
> val print_int : int result -> unit = <fun>
> # let print_float = ...
> # let x = new_result 10 "the number of elements in the knapsack";;
> val x : int result = ...
> # print_int x;;
> the number of elements in the knapsack is 10
> - : unit = ()
Here is the problem of this approach
# let complex_computation = fun x y -> x + y
val complex_computation : int -> int -> int = <fun>
let x = simple_computation () and
y = simple_computation ()
let z = complex_computation x y
Now I what to add a comment to x to print intermediate results and
check the first computation is correct. In your approach, this lifts x
: int on x : int result. But what will then be the type of
complex_computation ?
int result -> int -> int ?
int -> int result -> int ?
int result -> int result -> int ?
int result -> int result -> int result ?
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