Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
To: "Rafael 'Dido' Sevilla" <dido@imperium.ph>
Cc: John Goerzen <jgoerzen@complete.org>, <caml-list@inria.fr>
Subject: Re: [Caml-list] Observations on OCaml vs. Haskell
Date: Mon, 27 Sep 2004 14:34:46 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0409271417390.20651-100000@hkn.eecs.berkeley.edu> (raw)
In-Reply-To: <20040927202449.GA548@imperium.ph>


> > I've written several functions that can work with a "number-like"
> > type.  I don't really care if I get an integer, Int32, Int64, float,
> > or what But since these are all different types in OCaml, I am forced
> > to care, right down to using +, +., or Int64.add to perform basic
> > arithmetic.

[text cut]

> However, I do agree with you that the mess with OCaml having to add
> totally different operators to do arithmetic for integral and floating
> point types is a wart in what is otherwise an elegant language.  The
> compiler could very easily make the arithmetic operators polymorphic,
> and constrain the operands to be of the same (numeric) type, and signal
> an error if you attempt to, say, multiply an integer with a floating
> point number without doing the proper conversion.


The comparison operators '<' are polymorphic, but that does incur some
performance cost.  Richard Jones's wonderful tutorial on OCaml touches on
this under "Polymorphic types":

    http://www.merjis.com/developers/ocaml_tutorial/ch11


He 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.  I think OCaml's arithmetic operators are monomophic to avoid
the cost of polymorphism.



> Unless there's something in the design of the type system that prevents
> this from happening except at run-time...?

I wonder if the Cartesian Product Algorithm might be applicable to OCaml.
There's a paper about it here:

    http://research.sun.com/self/papers/cpa.html


where it sounds like it might be able to attack this problem.  I'd love to
be able to use just one '+' operator, rather than remember '+' vs '+.' vs
'+/'.  *grin*

-------------------
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


  reply	other threads:[~2004-09-27 21:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-27 19:08 John Goerzen
2004-09-27 20:24 ` Rafael 'Dido' Sevilla
2004-09-27 21:34   ` Danny Yoo [this message]
2004-09-28  7:22     ` Ville-Pertti Keinonen
2004-09-28 18:02       ` Jon Harrop
2004-09-29 14:26         ` Brian Hurt
2004-09-29 14:20           ` Jon Harrop
2004-09-29 15:03           ` Dmitry Lomov
2004-09-28 10:10     ` [Caml-list] Caml monomorphisation (was Observations on OCaml vs. Haskell) Diego Olivier Fernandez Pons
2004-09-28 12:01       ` Richard Jones
2004-09-28 17:50       ` Jon Harrop
2004-09-28  1:56   ` [Caml-list] Observations on OCaml vs. Haskell skaller
2004-09-28  9:31   ` Keith Wansbrough
2004-09-28  9:55     ` Rafael 'Dido' Sevilla
2004-09-27 21:11 ` Christophe TROESTLER
2004-09-28  1:32 ` Jacques GARRIGUE
2004-09-28  1:46 ` skaller
2004-09-28  8:27 ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0409271417390.20651-100000@hkn.eecs.berkeley.edu \
    --to=dyoo@hkn.eecs.berkeley.edu \
    --cc=caml-list@inria.fr \
    --cc=dido@imperium.ph \
    --cc=jgoerzen@complete.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox