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
Why + vs +. but "fake" parametric polymorphism for <
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Carlos Pita <cpitadev@y...>
Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for <

> Well, to reiterate Jacques warning, annotating the arguments and then 
> calling a function which is polymorphic won't magically cause the 
> polymorphic function to use the non-polymorphic comparisons.

  max a b = if a > b then a else b
  print_int (max 2 3);;

Ok, I understand. By inspection of code generated for the snippet above
one sees that albeit the max function is in fact inlined the compiler
won't optimize the comparison for ints. What is to be concluded here, if
any? Is the moral of the story that when inlining the compiler won't try
further optimizations beyond almost verbatim copy of code for the
inlined fragment, which was once and for all generated in isolation
without attending to specific contexts of use? So, if this is the case,
following the tutorial and your remarks the best bet is to specify types
for the arguments when defining a function so the compiler get the
chance to optimize it locally.


Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!