English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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 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