From: Siegfried Gonzi <siegfried.gonzi@stud.uni-graz.at>
To: Brian Hurt <brian.hurt@qlogic.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Easy solution in OCaml?
Date: Sat, 26 Apr 2003 15:45:28 +0200 [thread overview]
Message-ID: <3EAA8D78.8000006@stud.uni-graz.at> (raw)
In-Reply-To: <Pine.LNX.4.33.0304251004480.3160-100000@eagle.ancor.com>
>
>
>
>
Brian Hurt wrote:
>I find that if you're working against the compiler, either a) you haven't
>thought the problem through, b) there's an easy solution you're missing,
>or c) you have a bug.
>
I think this is a very interesting question. What I love about Scheme
(or even Python lists) is the fact that you can put into a list what you
want. I had a problem the other day which was as follows:
I have a Scheme function which extracts floating-point values from
strings located in a file:
==
12.33,43.4,4.56,nan,1.23
23.3,34.4,nan,1.2,0
...
==
The extracted floating point numbers become stored into an array:
(vector (vector 12.33 43.4 4.56 -1.0 1.23) (vector 23.3 34.4 -1.0 1.2 0.0))
My boss gave me a file which he urgently had to evaluate in order to
fullfill a time schedule (some measurements from the field of
experimental physics). But there was a problem, because the file was as
follows:
==
name1,2.23,2.23,23.4
name2,23.34,23.34,.223
...
==
The first entry was an annotation but my Scheme function expects a
string which can be converted to a floating point number. But Scheme is
your friend here, because one more line in my file-reading function and
you get something like this:
((name1 2.23 2.334) (name2 3.34 23.2 ...))
In Ocaml I would have to skip the first entry because it is not a
floating-point value. All my other functions were not affected, because
passing around arrays or lists does not mean you must put forward
floating-points or string arrays or whatever.
I agree upon that the above feature can sometimes lead to bad hacks,
because you the return value of a function can consist of a list where
you put things into the list which you decide later on whether you want
augment the list by other parameters, for example:
Your first version of the function has as return value: (list (list 2 3 4))
A year later you decide you want something like this: (list (list 2 3 4)
(vector 3 4 5) "hi guy")
The goody here is all your other functions which expect the output of
the above function must not be re-written, as opposed to Clean or OCaml
where you would have to re-write all your functions because the
structure of your return-list has changed.
>This is usefull for two reasons, in my experience: sometimes, it lets the
>compiler produce better code (for example, consider the function:
>let foo x y = x == y
>If you know that x and y will always be integers, doing:
>let foo (x:int) (y:int) = x == y
>allows the compiler to inline integer equals, rather than calling the
>generic compare function- much faster).
>
I doubt that type correctness is always better or leads to failure-free
program execution. Yesterday I faced the following situation: dividing
the two vectors:
(vector 0.0 0.0 23.34 23.4)
through
(vector 0.0 0.0 0.0 23.4)
I forgot to check that division by zero is not a good idea, but the good
old Bigloo compiler didn't rebel and had as output:
(vector #f #f #f 1.0)
Maybe a bad example because in OCaml you could use exceptions or
something like this, but in this case the OCaml program had aborted
(this is also true for C,...). I am not sure how long it would have gone
good, but the Scheme program had not aborted in a safety-critical
system-environment. I am really often surprised how forgiving Scheme and
also CommonLisp actually are in such situations.
Regards,
S. Gonzi
-------------------
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
next prev parent reply other threads:[~2003-04-26 14:57 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-04-25 6:05 Siegfried Gonzi
2003-04-25 8:19 ` sebastien FURIC
2003-04-25 15:46 ` Brian Hurt
2003-04-25 16:34 ` Ville-Pertti Keinonen
2003-04-26 13:45 ` Siegfried Gonzi [this message]
2003-04-26 21:51 ` Brian Hurt
2003-04-27 15:01 ` Siegfried Gonzi
2003-04-28 15:43 ` Brian Hurt
2003-04-29 5:46 ` John Max Skaller
2003-04-27 16:33 ` [Caml-list] Re: IEEE-754 (was: Easy solution in OCaml?) Christophe TROESTLER
2003-04-25 16:59 ` [Caml-list] Easy solution in OCaml? Markus Mottl
2003-04-26 6:25 ` Siegfried Gonzi
2003-04-27 14:13 ` Siegfried Gonzi
2003-04-27 16:54 ` Eray Ozkural
2003-04-28 5:00 ` Siegfried Gonzi
2003-04-28 17:45 ` malc
2003-04-28 18:16 ` Shivkumar Chandrasekaran
[not found] <20030427164326.34082.qmail@web41211.mail.yahoo.com>
2003-04-28 12:05 ` Siegfried Gonzi
2003-04-28 13:54 ` Noel Welsh
2003-04-28 14:22 ` David Brown
2003-04-28 14:38 ` sebastien FURIC
2003-04-28 18:14 ` Eray Ozkural
2003-05-03 14:37 ` John Max Skaller
2003-05-03 16:57 ` Eray Ozkural
2003-04-28 15:27 isaac gouy
2003-04-28 16:38 ` brogoff
2003-04-28 17:13 ` isaac gouy
2003-04-28 17:48 ` Brian Hurt
2003-04-28 17:50 ` brogoff
2003-04-28 18:31 ` Eray Ozkural
2003-04-29 6:46 ` Siegfried Gonzi
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=3EAA8D78.8000006@stud.uni-graz.at \
--to=siegfried.gonzi@stud.uni-graz.at \
--cc=brian.hurt@qlogic.com \
--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