The worst piece of syntax in Haskell
josef.svenningsson at gmail.com
Tue Feb 21 17:41:47 EST 2006
How fast can you tell me which classes are defined an instantiated in the
> class Monad m => MonadPlus m where ...
> class Ord a => Ix a where ...
> instance Integral a => Eq (Ratio a) where ...
How fast did you do it? And no, the correct answer is not Monad, Ord and
Integral. It is MonadPlus, Ix and Eq.
Ok, I guess you can see my point. My point is that the placement of class
constraints in class definitions, instance declarations and type signatures
is bad. Class constraints should *not* come first. It's hard on the eye. It
makes your eyes going back and forth looking for the most important thing
while trying to avoid the class constraints. Class constraints should come
*after* the thing they constrain.
This hit me pretty badly some time ago when I was writing a largish library
full of class declarations. After a while it became unwieldy to browse
through the code. It became overly difficult to find the right class
This is one of the things that the Clean people got right. In Clean, my
examples from above would look like:
> class MonadPlus m | Monad m where ...
> class Ix a | Ord a where ..
> instance Eq (Ratio a) | Integral a where ...
I'm not proposing we change this though. I realise that Haskell will have to
live with this bad syntax for its entire lifetime. It simply brakes too many
programs to change it. And having two alternative syntaxes with the goal of
eventually switching to the other would be awfully confusing. But even
though I don't propose to change this I had to let it off my chest. I feel
much better now.
All the best,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-prime