Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many syntactic forms does Haskell have?

Tags:

syntax

haskell

Master Norvig once said:

The beauty of Scheme is that the full language only needs 5 keywords and 8 syntactic forms. In comparison, Python has 33 keywords and 110 syntactic forms, and Java has 50 keywords and 133 syntactic forms. All those parentheses may seem intimidating, but Scheme syntax has the virtues of simplicity and consistency. (Some have joked that "Lisp" stands for "Lots of Irritating Silly Parentheses"; I think it stand for "Lisp Is Syntactically Pure".)

So how does Haskell compare?

like image 405
X10D Avatar asked Oct 16 '22 04:10

X10D


1 Answers

For Haskell 98, probably roughly the same order of magnitude as Python or Java.

It's hard to determine exactly what constitutes a "syntactic form". It looks like the Java count, for example, might have been taken from the number of extended BNF rules at the expression level and above (i.e., at the level where "identifier" is an atom), as on this Java SE syntax page where about 120 or so are listed. This also seems consistent with this page on Scheme, where I'd count about 14, ignoring rules that seem to be entirely concerned with the lexical structure of identifiers and literals. We're working with approximations here where 8 and 14 should be considered equal.

So, by that metric, my quick and dirty count from the Haskell 98 report section 9.5 Context-Free Syntax (which seems to be at roughly the same abstraction level as that Java reference) is 76. Again, we're working with approximations here where 76, 110, and 133 should all be considered equal, so Haskell == Python == Java.

It's also safe to say that, as per the comments, GHC specific syntax (pragmas, primitives, and many, many extensions) would easily double or triple that count.

All that being said, I'm not sure how useful this metric is. I don't dispute the claim that Scheme is a beautiful language, but I think the claim that Scheme is a beautiful language because (or mostly because) it has a small number of keywords and syntactic forms is, at best, an egregious oversimplification.

like image 143
K. A. Buhr Avatar answered Oct 18 '22 13:10

K. A. Buhr