This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] Why must types be always defined at the top level?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-06-24 (20:13) From: Olivier Andrieu Subject: Re: [Caml-list] Why must types be always defined at the top level?
``` William D. Neumann [Thu, 24 Jun 2004]:
> On Thu, 24 Jun 2004, John Hughes wrote:
> > 5. Why can I no longer type-annotate things I've written, so that
> >
> > let f x y z = (x = y) & (y = z)
> >
> > defines a function applicable to ALL types? I actually *liked*
> > being able to say something like
> >
> > let f x y z:int = (x = y) && (y = z)
> >
> > so that it would be restricted to ints.
>
> You can do this.  You just need to do:
> # let f x y (z:int) = (x = y) & (y = z);;
> val f : int -> int -> int -> bool = <fun>
>
> What you have above is annotating f, not z.

Actually, it's annotating the return value of f (ie the right hand
side of the =). To annotate f, you have to use this syntax :

# let f x y z : bool = (x = y) & (y = z) ;;
val f : 'a -> 'a -> 'a -> bool = <fun>
# let f : int -> int -> int -> bool = fun x y z -> (x = y) & (y = z) ;;
val f : int -> int -> int -> bool = <fun>

--
Olivier

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

```