Browse thread
[Caml-list] mystified by typing of optional arguments
-
Francois Rouaix
- Francois Thomasset
- Ville-Pertti Keinonen
- Eric C. Cooper
- Jacques Carette
- Jacques Garrigue
[
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: | Jacques Garrigue <garrigue@k...> |
| Subject: | Re: [Caml-list] mystified by typing of optional arguments |
From: Francois Rouaix <francois@rouaix.org>
> Hi all,
> The following example mystifies me
>
> let f ?opt x =
> match opt with
> | None -> x
> | Some dx -> x + dx
>
> let g x = x + 1
>
>
> let h1 = function
> | 0 -> [g]
> | _ -> [f; g]
>
>
> let h2 = function
> | _ -> [f; g]
>
>
> h1 is typable but not h2.
> Why is that ?
As stated in many places in the manual, type inference for optional
arguments is not principal.
But there is a now a -principal option to ocaml and ocamlc, which
attempts to recover principality, and gives more information in such
cases.
% ocaml -principal
Objective Caml version 3.06+27 (2003-03-31)
[...]
# let h1 = function
| 0 -> [g]
| _ -> [f; g]
^
;;
Warning: Eliminated optional argument without principality
val h1 : int -> (int -> int) list = <fun>
Note that -principal itself is available in ocaml 3.06, but would not
provide the above warning.
Jacques Garrigue
-------------------
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