List Info

Thread: "ocaml_beginners"::[] type pretty-printing on functional values




"ocaml_beginners"::[] type pretty-printing on functional values
country flaguser name
United States
2007-06-13 04:42:35

Hello all,

I've noticed that in the OCaml toplevel user-enforced type renaming always works with
non-functional values but not (always) with functional values
(some simple code below explains this). Is there an "elementary"; way
to fix this problem, without resorting to create a new module and .mli file just
for that ?

Ewan

(* Sample 1 : It works for non-functional values : the "my_large_banana" value is declared
with the typename I asked for. *)

Objective Caml version 3.09.3

# type banana=Banana of int;;
type banana = Banana of int
# type large_banana=banana;;
type large_banana = banana
# let my_banana=Banana(2006);;
val my_banana : banana = Banana 2006
# let my_large_banana=(my_banana:large_banana);;
val my_large_banana : large_banana = Banana 2006

(* Sample 2 : It does not work in the functional example below. Despite all
my attempts, I cannot force the type name of "declare_large"
to be "banana->large_banana". *)

# type banana=Banana of int;;
type banana = Banana of int
# type large_banana=banana;;
type large_banana = banana
# let declare_large1=
((function (x:banana)->(x:large_banana)):(banana->large_banana));;
val declare_large1 : large_banana -> large_banana = <fun>;
# let declare_large2=
((function (x:banana)->(x:&gt;large_banana)):(banana->large_banana));;
val declare_large2 : large_banana -> large_banana = <fun>;
# let declare_large3=(declare_large2:>(banana->large_banana));;
val declare_large3 : large_banana -> large_banana = <fun>;

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )