Browse thread
Ocaml compiler features
[
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: | Tom <tom.primozic@g...> |
| Subject: | Re: [Caml-list] Ocaml compiler features |
>
>
>
> I think this is the uncommon case, and deserves the parentheses:
> x <- (if y then a else b) ;
It's not the uncommon case... It's what's the ?: operator for C++ and Java.
I guess it's very common indeed.
I think I'm arguing that the precedence of if/then/else is too high, and
> maybe should be lowered. Of course this isn't a reasonable thing to
> ask, because it'll likely break existing code. Anyone with a way to
> have my cake and eat it too?
>
>
Look at nemerle [1], I believe they have the if/then/else construct with the
else clause mandatory, and for cases where in OCaml it is ommited, they
would use the when keyword. This solves your problem:
if y=1 then
print_int y;
print_int 2;
else
print_string "not one"
is same as
if y=1 then
( print_int y;
print_int 2; )
else
print_string "not one"
but
when y=1 then
print_int y;
print_int 2;
would be (in OCaml)
(if y=1 then print_int y); print_int 2