Hi all,<br><br>Quickly!<br><br>How fast can you tell me which classes are defined an instantiated in the code below?<br><br>&gt; class Monad m =&gt; MonadPlus m where ...<br>&gt; <br>&gt; class Ord a =&gt; Ix a where ...<br>
&gt;<br>&gt; instance Integral a =&gt; Eq (Ratio a) where ...<br><br>How fast did you do it? And no, the correct answer is not Monad, Ord and Integral. It is MonadPlus, Ix and Eq.<br><br>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.
<br><br>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 definition.
<br><br>This is one of the things that the Clean people got right. In Clean, my examples from above would look like:<br><br>&gt; class MonadPlus m | Monad m where ...<br>&gt; <br>&gt; class Ix a | Ord a where ..<br>&gt;<br>
&gt; instance Eq (Ratio a) | Integral a where ...<br><br>Much better!<br><br>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.<br><br>All the best,<br><br>/Josef<br>