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] type annotations for function values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-25 (19:44)
From: fis@w...
Subject: [Caml-list] type annotations for function values

hi all,

as the grammar and type system of ocaml are so sophisticated, i am
often having trouble narrowing down the source of an error message.
the answer are of course type annotations, "i know this function here
must have this type, trust me", something of that ilk.

now this is easy:

  let f (x : float) (y : float) = 3 in 4;;

but what do i do if i want to write down an explicit type for f?  the
only thing i found that works is

  let f : (float -> float -> int) = (fun x y -> 3) in 4;;

which is horribly inelegant.  why can't i do something like this?

  let (f : (float -> float -> int)) x y = 3 in 4;;
  let ((f x y) : (float -> float -> int)) = 3 in 4;;
  let ((f (x : float) (y : float)) : int) = 3 in 4;;

the last one seems wrong, but anyway, i am still hoping that something
like this exists.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: