From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA25694; Sat, 26 Apr 2003 16:57:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA26053 for ; Sat, 26 Apr 2003 16:57:12 +0200 (MET DST) Received: from teutates.kfunigraz.ac.at (TEUTATES.kfunigraz.ac.at [143.50.129.26]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h3QEvBH11241 for ; Sat, 26 Apr 2003 16:57:12 +0200 (MET DST) Received: from localhost (localhost.localdomain [127.0.0.1]) by teutates.kfunigraz.ac.at (Postfix) with ESMTP id 554AD3D2221; Sat, 26 Apr 2003 16:57:11 +0200 (CEST) Received: from teutates.kfunigraz.ac.at ([127.0.0.1]) by localhost (teutates.kfunigraz.ac.at [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21446-10; Sat, 26 Apr 2003 16:57:10 +0200 (CEST) Received: from stud.uni-graz.at (IGAM08AV.kfunigraz.ac.at [143.50.39.35]) by teutates.kfunigraz.ac.at (Postfix) with ESMTP id D2BB93D2191; Sat, 26 Apr 2003 16:57:09 +0200 (CEST) Message-ID: <3EAA8D78.8000006@stud.uni-graz.at> Date: Sat, 26 Apr 2003 15:45:28 +0200 From: Siegfried Gonzi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020204 X-Accept-Language: en-us MIME-Version: 1.0 To: Brian Hurt Cc: caml-list@inria.fr Subject: Re: [Caml-list] Easy solution in OCaml? References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at stud.uni-graz.at X-Spam: no; 0.00; siegfried:01 gonzi:01 stud:99 caml-list:01 bug:01 python:01 0.0:01 fullfill:01 passing:01 hacks:01 goody:01 re-write:01 foo:01 generic:01 function-:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > > > 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