Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jens Olsson <jenso@csd.uu.se>
To: caml-list@inria.fr
Subject: tuple vs curried, records vs variants
Date: Wed, 28 Jul 1999 20:48:44 +0200 (MET DST)	[thread overview]
Message-ID: <14239.20620.728265.612382@zeppo.csd.uu.se> (raw)

Hello,

(Yet another 'newbie'-question for anyone who has the patience)

Different sources (such as the documentation) says curried functions
are to prefer rather than functions using tuples, if speed is of any
concern anyway.

Before realizing this and as I'm used to the SML dialect, I
implemented a module for three-dimensional vectors using 'tupled'
functions first. Upon a question regarding speed I also got the
recommendation to use records instead of a variant with a single
constructor.

After making all the functions curried instead, and changing the
implementation to use records instead I measured the performance of
the two implementation and realized to my surprise that the old
version (the implementation using variants and tupled functions) was
faster (than the one using records and curried functions). So my
questions are:

1) Is this really correct? I tried the implementations on two different
   architectures and got the same result. One can ask if the test program
   wasn't 'good enough'.

2) Is it only a "religious" question to use single-valued variants
   instead of records (when defining a datatype) or has speed something
   to do with it? If the former case applies, which one should I use
   and why? Any other aspects?

3) BTW, what is the "best" way of writing pattern-matching functions,
   ie   [let f x = match ....] or [let f = function x -> ...]?
   (Maybe we're getting 'religious' here as well?)

I guess my code is not of interest so I'll exclude it but if someone
thinks it's relevant I can provide it.

Thanks in advance for any response to my somewhat basic questions...

best regards

Jens

--
--[ Jens Olsson ]-----------------------------------------------------
  [Address]            [Phone]                 [WWW]
  Djäknegatan 13, 1tr  Home: 018 -  24 88 77   jenso@csd.uu.se     
  754 23 Uppsala       Work: 018 - 471 76 85   www.csd.uu.se/~jenso
  SWEDEN               Cell: CEASED!!!         ICQ UID 8955231
---------------------------------[ CS student @ Uppsala University ]--




             reply	other threads:[~1999-07-30  1:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-28 18:48 Jens Olsson [this message]
1999-08-02 20:17 ` Xavier Leroy

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=14239.20620.728265.612382@zeppo.csd.uu.se \
    --to=jenso@csd.uu.se \
    --cc=caml-list@inria.fr \
    /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