code length in Haskell, a comparison

There is some interesting data in the article at: Code Length Measured in 14 Languages http://blog.wolfram.com/2012/11/14/code-length-measured-in-14-languages/ basically comparing program lengths in various languages, and some ensuing discussion of how this relates to language expressiveness, etc. (He does all of his analysis in Mathematica, which is the goal of the article.) It is interesting to see how well Haskell showed in the data; and it would also be interesting to see how well it could replicate the analysis example which was a nice example of web data scraping! The data is the length of a series of programs written in a number of languages (data from: http://rosettacode.org/wiki/Rosetta_Code). (The columns don't map well to text only, Haskell column marked with ≡≡≡≡ (Why doesn't this list support HTML?)). See nicer version at: http://pastehtml.com/view/ciy7woohv.rtxt The average for Haskell of 1.89 means that on the average the same program in Haskell takes ~2x in the other languages. Given the correlation of size to clarity, complexity, effort, and errors, this is a good thing! :-) Code Size relative to Mathematica Larger numbers indicate that the language on top needs more code. C C++ Fortran Java CLisp Python C# JavaScript R MATLAB Clojure Pascal Haskell Ruby Average ??????????? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ≡≡≡≡ ???? Mathematica 17.0 9.1 8.1 6.4 6.3 7.2 6.4 5.0 3.2 3.2 1.6 5.8 3.5 5.2 6.29 Ruby 2.7 1.8 1.9 1.3 1.1 1.1 1.5 1.0 0.7 0.9 0.4 1.4 0.7 1.27 Haskell 3.6 2.7 2.5 2.0 1.6 1.7 2.2 1.5 1.1 1.5 0.7 2.1 1.4 1.89 Pascal 2.2 1.5 1.2 0.8 0.8 0.8 1.0 0.8 0.5 0.6 0.2 0.5 0.7 0.89 Clojure 8.8 5.3 5.2 3.6 3.7 3.3 3.8 2.5 1.9 2.9 5.0 1.5 2.6 3.85 MATLAB 3.6 2.4 1.8 1.1 1.4 1.1 1.7 0.9 0.8 0.3 1.6 0.7 1.1 1.42 R 4.7 3.3 2.4 1.9 1.8 1.7 2.1 1.5 1.3 0.5 2.2 0.9 1.4 1.98 JavaScript 2.8 2.1 1.9 1.2 1.2 1.1 1.6 0.7 1.1 0.4 1.3 0.7 1.0 1.31 C# 2.0 1.4 1.3 0.9 0.8 0.8 0.6 0.5 0.6 0.3 1.0 0.5 0.7 0.87 Python 2.2 1.6 1.5 1.1 0.9 1.2 0.9 0.6 0.9 0.3 1.3 0.6 0.9 1.07 Common Lisp 2.8 1.8 1.6 1.3 1.1 1.3 0.8 0.6 0.7 0.3 1.3 0.6 0.9 1.16 Java 2.1 1.4 1.5 0.8 0.9 1.1 0.8 0.5 0.9 0.3 1.2 0.5 0.8 0.98 Fortran 1.4 1.0 0.7 0.6 0.7 0.8 0.5 0.4 0.6 0.2 0.8 0.4 0.5 0.66 C++ 1.4 1.0 0.7 0.6 0.6 0.7 0.5 0.3 0.4 0.2 0.7 0.4 0.6 0.61 C 0.7 0.7 0.5 0.4 0.5 0.5 0.4 0.2 0.3 0.1 0.5 0.3 0.4 0.41 ???????????? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ≡≡≡≡ ???? Overall: 4.1 2.58 2.3 1.68 1.56 1.61 1.85 1.27 0.85 1.14 0.41 1.86 0.83 1.29 Overall Ranking: Clojure 0.41 Haskell 0.83 R 0.85 MATLAB 1.14 JavaScript 1.27 Ruby 1.36 Common Lisp 1.56 Python 1.61 C++ 1.68 C# 1.85 Pascal 1.86 Fortran 2.33 C++ 2.58 C 4.09 -------------------------------------------

I am leery of code comparisons (but not Timothy Leary of them).
Clojure being a JVM language has the advantage of the massive Java
class libraries.
If Haskell could tie in fairly seamlessly to the Java class libraries ...
If more developers learned the need for finer grained abstraction ...
On Mon, Nov 19, 2012 at 7:55 PM, Gregory Guthrie
There is some interesting data in the article at:
Code Length Measured in 14 Languages http://blog.wolfram.com/2012/11/14/code-length-measured-in-14-languages/
basically comparing program lengths in various languages, and some ensuing discussion of how this relates to language expressiveness, etc. (He does all of his analysis in Mathematica, which is the goal of the article.)
It is interesting to see how well Haskell showed in the data; and it would also be interesting to see how well it could replicate the analysis example which was a nice example of web data scraping!
The data is the length of a series of programs written in a number of languages (data from: http://rosettacode.org/wiki/Rosetta_Code). (The columns don't map well to text only, Haskell column marked with ≡≡≡≡ (Why doesn't this list support HTML?)). See nicer version at: http://pastehtml.com/view/ciy7woohv.rtxt
The average for Haskell of 1.89 means that on the average the same program in Haskell takes ~2x in the other languages. Given the correlation of size to clarity, complexity, effort, and errors, this is a good thing! :-)
Massive Snip!
Overall Ranking: Clojure 0.41 Haskell 0.83 R 0.85 MATLAB 1.14 JavaScript 1.27 Ruby 1.36 Common Lisp 1.56 Python 1.61 C++ 1.68 C# 1.85 Pascal 1.86 Fortran 2.33 C++ 2.58 C 4.09 -------------------------------------------
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- -- Regards, KC

I find myself wondering where Rebol would stand in this.
On Nov 19, 2012 8:35 PM, "KC"
I am leery of code comparisons (but not Timothy Leary of them).
Clojure being a JVM language has the advantage of the massive Java class libraries.
If Haskell could tie in fairly seamlessly to the Java class libraries ...
If more developers learned the need for finer grained abstraction ...
On Mon, Nov 19, 2012 at 7:55 PM, Gregory Guthrie
wrote: There is some interesting data in the article at:
Code Length Measured in 14 Languages
http://blog.wolfram.com/2012/11/14/code-length-measured-in-14-languages/
basically comparing program lengths in various languages, and some
(He does all of his analysis in Mathematica, which is the goal of the
ensuing discussion of how this relates to language expressiveness, etc. article.)
It is interesting to see how well Haskell showed in the data; and it
would also be interesting to see how well it could replicate the analysis example which was a nice example of web data scraping!
The data is the length of a series of programs written in a number of
(The columns don't map well to text only, Haskell column marked with ≡≡≡≡ (Why doesn't this list support HTML?)). See nicer version at: http://pastehtml.com/view/ciy7woohv.rtxt
The average for Haskell of 1.89 means that on the average the same
languages (data from: http://rosettacode.org/wiki/Rosetta_Code). program in Haskell takes ~2x in the other languages.
Given the correlation of size to clarity, complexity, effort, and errors, this is a good thing! :-)
Massive Snip!
Overall Ranking: Clojure 0.41 Haskell 0.83 R 0.85 MATLAB 1.14 JavaScript 1.27 Ruby 1.36 Common Lisp 1.56 Python 1.61 C++ 1.68 C# 1.85 Pascal 1.86 Fortran 2.33 C++ 2.58 C 4.09 -------------------------------------------
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- -- Regards, KC
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Why C++ appears twice in the Overall rank?
2012/11/20 Gregory Guthrie
There is some interesting data in the article at:
Code Length Measured in 14 Languages
http://blog.wolfram.com/2012/11/14/code-length-measured-in-14-languages/
basically comparing program lengths in various languages, and some ensuing discussion of how this relates to language expressiveness, etc. (He does all of his analysis in Mathematica, which is the goal of the article.)
It is interesting to see how well Haskell showed in the data; and it would also be interesting to see how well it could replicate the analysis example which was a nice example of web data scraping!
The data is the length of a series of programs written in a number of languages (data from: http://rosettacode.org/wiki/Rosetta_Code). (The columns don't map well to text only, Haskell column marked with ≡≡≡≡ (Why doesn't this list support HTML?)). See nicer version at: http://pastehtml.com/view/ciy7woohv.rtxt
The average for Haskell of 1.89 means that on the average the same program in Haskell takes ~2x in the other languages. Given the correlation of size to clarity, complexity, effort, and errors, this is a good thing! :-)
Code Size relative to Mathematica Larger numbers indicate that the language on top needs more code.
C C++ Fortran Java CLisp Python C# JavaScript R MATLAB Clojure Pascal Haskell Ruby Average ??????????? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ≡≡≡≡ ???? Mathematica 17.0 9.1 8.1 6.4 6.3 7.2 6.4 5.0 3.2 3.2 1.6 5.8 3.5 5.2 6.29 Ruby 2.7 1.8 1.9 1.3 1.1 1.1 1.5 1.0 0.7 0.9 0.4 1.4 0.7 1.27 Haskell 3.6 2.7 2.5 2.0 1.6 1.7 2.2 1.5 1.1 1.5 0.7 2.1 1.4 1.89 Pascal 2.2 1.5 1.2 0.8 0.8 0.8 1.0 0.8 0.5 0.6 0.2 0.5 0.7 0.89 Clojure 8.8 5.3 5.2 3.6 3.7 3.3 3.8 2.5 1.9 2.9 5.0 1.5 2.6 3.85 MATLAB 3.6 2.4 1.8 1.1 1.4 1.1 1.7 0.9 0.8 0.3 1.6 0.7 1.1 1.42 R 4.7 3.3 2.4 1.9 1.8 1.7 2.1 1.5 1.3 0.5 2.2 0.9 1.4 1.98 JavaScript 2.8 2.1 1.9 1.2 1.2 1.1 1.6 0.7 1.1 0.4 1.3 0.7 1.0 1.31 C# 2.0 1.4 1.3 0.9 0.8 0.8 0.6 0.5 0.6 0.3 1.0 0.5 0.7 0.87 Python 2.2 1.6 1.5 1.1 0.9 1.2 0.9 0.6 0.9 0.3 1.3 0.6 0.9 1.07 Common Lisp 2.8 1.8 1.6 1.3 1.1 1.3 0.8 0.6 0.7 0.3 1.3 0.6 0.9 1.16 Java 2.1 1.4 1.5 0.8 0.9 1.1 0.8 0.5 0.9 0.3 1.2 0.5 0.8 0.98 Fortran 1.4 1.0 0.7 0.6 0.7 0.8 0.5 0.4 0.6 0.2 0.8 0.4 0.5 0.66 C++ 1.4 1.0 0.7 0.6 0.6 0.7 0.5 0.3 0.4 0.2 0.7 0.4 0.6 0.61 C 0.7 0.7 0.5 0.4 0.5 0.5 0.4 0.2 0.3 0.1 0.5 0.3 0.4 0.41 ???????????? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ???? ≡≡≡≡ ???? Overall: 4.1 2.58 2.3 1.68 1.56 1.61 1.85 1.27 0.85 1.14 0.41 1.86 0.83 1.29
Overall Ranking: Clojure 0.41 Haskell 0.83 R 0.85 MATLAB 1.14 JavaScript 1.27 Ruby 1.36 Common Lisp 1.56 Python 1.61 C++ 1.68 C# 1.85 Pascal 1.86 Fortran 2.33 C++ 2.58 C 4.09 -------------------------------------------
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Feng, Boqun School of Software,Shanghai Jiao Tong University

On 20/11/2012, at 4:55 PM, Gregory Guthrie wrote:
There is some interesting data in the article at:
Code Length Measured in 14 Languages http://blog.wolfram.com/2012/11/14/code-length-measured-in-14-languages/
basically comparing program lengths in various languages, and some ensuing discussion of how this relates to language expressiveness, etc. (He does all of his analysis in Mathematica, which is the goal of the article.)
I'm not sure how interesting it actually is. Let's study just one example: the digit sum problem. "This task is to take a Natural Number in a given Base and return the sum of its digits." We are not given any bounds on the size of the Natural Number nor any bounds on the Range. Arguably, the code for almost all of the programming languages shown is *wrong* due to making unwarranted assumptions about integer size. The Haskell example there is digsum base = f 0 where f a 0 = a f a n = f (a+r) q where (q,r) = n `divMod` base main = print $ digsum 16 255 -- "FF": 15 + 15 = 30 Since some other examples assume the base is 2..16, so may we. In that case, import Data.Char import Numeric digsum b n = sum . map digitToInt $ showIntAtBase b intToDigit n "" will do the job, and as an exercise in golfing myself, import Numeric digsum b n = sum . map fromEnum $ showIntAtBase b toEnum n "" will also do it, and should work for larger bases. In this particular test, Mathematica happens to score well because it already has IntegerDigits[number{, base}?] in its library. So at least this exercise is much more about "what happens to be available already in the library for this language" than about anything intrinsic to the language. There is worse. Some versions read test data, while some have a small number of test cases built in, and they do not agree about which test cases are provided. Looking at some other problems, some tasks have versions that use code that is published on the web but not part of the language standard and not included (or counted!) at the Rosetta site itself. There are lots of things you can learn by looking at the Rosetta site. I am not sure that the compactness of languages is one of them.
participants (6)
-
Darren Grant
-
Ertugrul Söylemez
-
Feng, Boqun
-
Gregory Guthrie
-
KC
-
Richard O'Keefe