From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 79361BBE1 for ; Thu, 12 Oct 2006 07:41:28 +0200 (CEST) Received: from smtp106.mail.mud.yahoo.com (smtp106.mail.mud.yahoo.com [209.191.85.216]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id k9C5fR2Q020153 for ; Thu, 12 Oct 2006 07:41:27 +0200 Received: (qmail 37553 invoked from network); 12 Oct 2006 05:41:23 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.ar; h=Received:Subject:From:To:In-Reply-To:References:Content-Type:Date:Message-Id:Mime-Version:X-Mailer:Content-Transfer-Encoding; b=DoSfUozjIbtr51GKgpf6FkaAT63oGWI1fBUwnr3ZZadEyh++GUtYnRY28zp6p2C0lFZgH9GsvMx9Hy5W28OinSngjPyGp7SuJfttBGqDH8Qv+2BTKBQzpJBLudJROwLzvDnSz/Bmdq7FGZakR3ouSWyUJniv+FPnMMUqyHC+nyU= ; Received: from unknown (HELO ?192.168.0.100?) (cpitadev@201.254.106.107 with plain) by smtp106.mail.mud.yahoo.com with SMTP; 12 Oct 2006 05:41:22 -0000 Subject: Re: [Caml-list] Why + vs +. but "fake" parametric polymorphism for < From: Carlos Pita To: caml-list@yquem.inria.fr In-Reply-To: <1160630365.7649.20.camel@monad> References: <1160630365.7649.20.camel@monad> Content-Type: text/plain Date: Thu, 12 Oct 2006 02:41:20 -0300 Message-Id: <1160631680.7649.27.camel@monad> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 452DD587.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; parametric:01 polymorphism:01 umh:01 compiler:01 val:01 ocaml:01 ocaml:01 inference:01 parametric:01 polymorphism:01 subtyping:01 compiler:01 bool:01 generality:01 beginner's:01 Umh, soon after writing my previous post I found out an interesting chapter in the tutorial giving an exact example of asm code generated by the compiler for comparison operator <: # let max a b = if a > b then a else b;; val max : 'a -> 'a -> 'a = ===> [...] ; Call the C "greaterthan" function (in the OCaml library). pushl %ebx pushl %eax movl $greaterthan, %eax call caml_c_call .L102: addl $8, %esp ; If the C "greaterthan" function returned 1, jump to .L100 [...] Pretty expensive for a simple int comparison I would say. Which is the way to go? I bet for-loops are optimized for int arithmetic/comparisons, aren't they? Thank you again. Regards, Carlos On Thu, 2006-10-12 at 02:19 -0300, Carlos Pita wrote: > Hi all! > > I would like to implement some number crunching inner loops for dsp > stuff with ocaml. I'm a newcomer to the language with strong > scheme/python background and trying to come into terms with type > inference, parametric polymorphism and structural subtyping. One thing > than I'm pretty fond of is the difference between floating point and > integer basic mathematical operators. I guess the compiler is able to > generate specific and more efficient code for each case without further > analysis. But then I found out that comparison operators offer some kind > of adhoc polymorphism in the guise of parametric one: > > # (<);; > - : 'a -> 'a -> bool = > > Is there any reason for this apparently inconsistent design? Would the > generality of < be against performance if for example, say, my critical > inner loops check against a top limit value thousands of times per > second? I'm afraid that the implementation of such a generic operator, > which is so different for numerical integer comparison than v.gr for > string lexicographical comparison, would incur into some run time > overhead. But, as I've said at the beginning, I'm just a newbie and most > probably there is a coherent explanation for all this confusion. > > Thank you in advance. > Best regards, > Carlos > > > > > > > > __________________________________________________ > Pregunt. Respond. Descubr. > Todo lo que queras saber, y lo que ni imaginabas, > est en Yahoo! Respuestas (Beta). > Probalo ya! > http://www.yahoo.com.ar/respuestas > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs __________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas