Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Observations on OCaml vs. Haskell
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@e...>
Subject: [Caml-list] Caml monomorphisation (was Observations on OCaml vs. Haskell)
    Bonjour,

> [Richard Jones] shows that:
>
> ;;;
> let max a b =
>     if a > b then a else b
> in
>     print_int (max 2 3)
> ;;;
>
>
> uses the polymorphic version of '>', even though the use of max here uses
> only ints.

Why doesn't Caml compiler specialize the type of [max] ?

Richard Jones' tutorial says one can help the compiler by specifying
types for one or more arguments (type annotations). Does this work if
the type annotation is in the .mli file or only in the .ml file inside
the function definition ?

let max : int -> int -> int = fun x y ->
  if x < y then y else x

wrt

let max = fun x y -> if x < y then y else x

val max : int -> int -> int


        Diego 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