The worst piece of syntax in Haskell

Ben Rudiak-Gould Benjamin.Rudiak-Gould at
Wed Feb 22 12:04:02 EST 2006

Ashley Yakeley wrote:
>   foo :: (Monad m) => [m a] -> m [a]
>   instance Integral a => Eq (Ratio a)
>   class Monad m <= MonadPlus m

I think the most consistent (not most convenient!) syntax would be

    foo :: forall m a. (Monad m) => [m a] -> m [a]
    instance forall a. (Integral a) => Eq (Ratio a) where {...}
    class MonadPlus m. (Monad m) && {...}

There's implicit forall quantification in instance declarations. It's 
currently never necessary to make it explicit because there are never type 
variables in scope at an instance declaration, but there's no theoretical 
reason that there couldn't be. There's no implicit quantification in class 
declarations---if you added a quantifier, it would always introduce exactly 
the type variables that follow the class name. I think it's better to treat 
the class itself as the quantifier. (And it's more like existential 
quantification than universal, hence the && instead of =>.)

As far as syntax goes, I like

    foo :: forall m a | Monad m. [m a] -> m [a]
    class MonadPlus m | Monad m where {...}

but I'm not sure what to do about the instance case, since I agree with the 
OP that the interesting part ought to come first instead of last.

-- Ben

More information about the Haskell-prime mailing list