OT (partially): about promotion of integers

bearophile bearophileHUGS at lycos.com
Tue Dec 11 15:59:28 PST 2012


Walter Bright:

> I don't notice anyone reaching for Lisp or Ocaml for high 
> performance applications.

Nowadays CommonLisp is not used much for anything (people at ITA 
use it to plan flights, their code is efficient, algorithmically 
complex, and used for heavy loads).

OCaML on the other hand is regarded as quite fast (but it's not 
much used in general), it's sometimes used for its high 
performance united to its greater safety, so someone uses it in 
automatic high-speed trading:

https://ocaml.janestreet.com/?q=node/61
https://ocaml.janestreet.com/?q=node/82


>> I think the compiler doesn't perform on BigInts the 
>> optimizations it does on
>> ints, because it doesn't know about bigint properties.
>
> I think the general lack of interest in bigints indicate that 
> the builtin types work well enough for most work.

Where do you see this general lack of interest in bigints? In D 
or in other languages?

I use bigints often in D. In Python we use only bigints. In 
Scheme, OcaML and Lisp-like languages multi-precison numbers are 
the default ones. I think if you give programmers better bigints 
(this means efficient and usable as naturally as ints), they will 
use them.

I think currently in D there is no way to make bigints as 
efficient as ints because there is no ways to express in D the 
full semantics of integral numbers, that ints have. This is a 
language limitation. One way to solve this problem, and keep 
BigInts as Phobos code, is to introduce a built-in attribute 
that's usable to mark user-defined structs as int-like.

----------------------

deadalnix:

>But OCaml is really very performant.<

It's fast considering it's a mostly functional language.

OCaML Vs C++ in the Shootout:

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=ocaml&lang2=gpp

Versus Haskell:
http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=ocaml&lang2=ghc

But as usual you have to take such comparisons cum grano salis, 
because there are a lot more people working on the GHC compiler 
and because the Shootout Haskell solutions are quite un-idiomatic 
(you can see it also from the Shootout site itself, taking a look 
at the length of the solutions) and they come from several years 
of maniac-level discussions (they have patched the Haskell 
compiler and its library several times to improve the results of 
those benchmarks):

http://www.haskell.org/haskellwiki/Shootout


>I don't know how it handle integer internally.<

It uses tagged integers, that are 31 or 63 bits long, the tag on 
the less significant side:

http://stackoverflow.com/questions/3773985/why-is-an-int-in-ocaml-only-31-bits

Bye,
bearophile


More information about the Digitalmars-d mailing list