caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Strange observation on polymorphic '<'
@ 2004-11-30 20:30 Ritesh Kumar
  2004-12-01 23:17 ` [Caml-list] " Damien Doligez
  0 siblings, 1 reply; 12+ messages in thread
From: Ritesh Kumar @ 2004-11-30 20:30 UTC (permalink / raw)
  To: caml-list

Hi,
I saw this on the site http://merjis.com/developers/ocaml_tutorial/ch11
The author says that even if the types of a function (let max a b = if 
a>b then a else b)which internally uses the '>' operator are known (by 
type inference) and are found to be ints, the ocamlopt compiler still 
calls the generic 'greaterthan' function written in C to compare them. 
This seems rather an over kill when a simple comparison instruction 
could have done the job. Am I missing something here? Let us assume 
that the function which internally uses the '<' operator is used only 
in the context of integers inside the program.

Ritesh
--
What you see is an illusion... well protected, well cherished only by 
you.


^ permalink raw reply	[flat|nested] 12+ messages in thread
* Fw: [Caml-list] Missing a function
@ 2005-01-30  9:53 Frédéric Gava
  2005-01-30 12:14 ` Olivier Andrieu
  0 siblings, 1 reply; 12+ messages in thread
From: Frédéric Gava @ 2005-01-30  9:53 UTC (permalink / raw)
  To: caml-list

Hi,
>
> > Another option is to build on top of the stdlib Map functor another
> > functor that keeps track of the cardinal of a map :
> >
> > module CMap = functor (Ord : Map.OrderedType) ->
> >   (struct
> >     module M = Map.Make (Ord)
> >
> >     type key = M.key
> >     type 'a t = int * 'a M.t
> >
> >     let cardinal = fst
> >
> >     let empty = 0, M.empty
> >
> >     let add k v (n, m) = (n + 1, M.add k v m)
> >
> >     let find k (_, m) = M.find k m
> >
> > ....
> >    : sig
> >        include Map.S
> >        val cardinal : 'a t -> int
> >      end)
> >
Hum. To remove an element, you have to test is its exists or not before
decrease n. It could be to much cost expansive...no ?

Regards,
Frédéric Gava



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-02-04 20:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-30 20:30 Strange observation on polymorphic '<' Ritesh Kumar
2004-12-01 23:17 ` [Caml-list] " Damien Doligez
2004-12-03  7:24   ` Ritesh Kumar
2004-12-03  8:22     ` Ville-Pertti Keinonen
2004-12-04 11:05       ` Missing a function Frédéric Gava
2004-12-04 13:25         ` [Caml-list] " sejourne_kevin
2004-12-04 14:13           ` Frédéric Gava
2005-01-29 19:34             ` Radu Grigore
2005-01-29 19:55               ` Radu Grigore
2005-01-29 21:05               ` Olivier Andrieu
2005-02-04 20:18               ` Radu Grigore
2005-01-30  9:53 Fw: " Frédéric Gava
2005-01-30 12:14 ` Olivier Andrieu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).