[Haskell-cafe] Re: Re: Allowing hyphens in identifiers

Maciej Piechotka uzytkownik2 at gmail.com
Wed Dec 9 18:24:15 EST 2009

On Thu, 2009-12-10 at 11:54 +1300, Richard O'Keefe wrote:
> On Dec 9, 2009, at 10:54 PM, Maciej Piechotka wrote:
> > You mean to parse a - b differently then a-b? You don't have the  
> > problem
> > in LISP as AFAIR you use (- a b) but in Haskell it would be a problem.
> It's a problem that COBOL solved a long time ago:
> Haskell already has this problem with ".", where we generally need
> to put spaces around "." with the meaning "composition" and not
> put spaces around other uses.

Well. http://en.wikipedia.org/wiki/Backward_compatibility

About '.' - there are two contexts in which it is used:
- Hierarchical modules: In which first letters (except maybe last one)
are capitalized
- Composition: In which first letters are not capitalized

In combination of those I belive there is no disambiguoty since the
lower case words functions as terminators. While it can be discussed as
an error of the past it is not the problem that spaces creates problems:
ghci> :t head . tail
head . tail :: [a] -> a
ghci> :t head .tail
head .tail :: [a] -> a
ghci> :t head.tail
head.tail :: [a] -> a

Or even:
ghci> :t
  :: a -> IO a

Even in hugs:
Hugs> :t head.tail
head . tail :: [a] -> a
Hugs> :t head . tail
head . tail :: [a] -> a
Hugs> :t head .tail
head . tail :: [a] -> a
Hugs> :t head.tail
head . tail :: [a] -> a
Main> :t
readIORef . unsafePerformIO . newIORef :: a -> IO a

I would question sanity of using . here but it is not the case that we
get flood of posts why adding/removing space next to ./- causes any
problems. People with practically any programmin backround would expect
a-b be equivalent to a - b. Sometimes this 2 spaces are needed to fit in
72/80 columns.

> This is something someone could easily try out by writing a trivial
> preprocessor to convert hyphens with letters on each side to
> underscores.  See how it works.
> Given the amazinglyUglyAndUnreadably baStudlyCaps namingStyle that
> went into Haskell forNoApparentReasonThatIHaveEverHeardOf, it might
> be nice to have a wee preprocessor that turned
> 	<lower case letter one> _ <lower case letter two>
> into	<lower case letter one> <Upper case letter two>
> so that I could write take_while and Haskell could see takeWhile.
> [I'm writing this in MacOS X Mail.  "takeWhile" is underlined in
> red as a spelling mistake, "take_while" is not.  Maybe they know
> something...]
> Here is such a preprocessor.  This is meant for people to try out.
> I don't claim that it's perfect, it's just a quick hack.

Personally I don't have any strong feelings about conventions as long as
they are consistent within one language. Camel cases are no more
uncommon then the underscore and they saved space in the past (ok. now
it does not matter) and hyphen is very rarly used (to not have problem
with minus). 

For example:
- Java - camel cases both in classes and methods (convention very
similar to Haskell)
- .Net - the same (but first letter of method is capitalized)
- Python - underscore
- C/C++ - Veries


More information about the Haskell-Cafe mailing list