9
votes

In an attempt to make a sane(r) alternative to Haskell's numeric type system, the devs of numeric-prelude slipped up and decided to name all of their type classes C. Aside from making the docs totally confusing, this means that I have to fully qualify all uses of the typeclasses:

import qualified Algebra.Additive (C)
import qualified Algebra.Ring (C)
...

newtype Foo a = Foo a

instance (Algebra.Additive.C a) => Algebra.Additive.C (Foo a) where ...

myadd :: (Algebra.Additive.C a) => a -> a -> a
myadd a b = ...

Also, since NumericPrelude has finer grained typeclasses, I usually have to import several different NumericPrelude modules. I can simplify this a little by defining top-level constraint synonyms:

{-# LANGUAGE ConstraintKinds #-}

module NPSynonyms (Additive) where

import qualified Algebra.Additive (C)

type Additive a = (Algebra.Additive.C a)

which allows me to make sane functions:

myadd :: (Additive a) => a -> a -> a
myadd a b = ...

However, when I need to define an instance, I still have to (also) import the original NumericPrelude class:

{-# LANGUAGE ConstraintKinds #-}

import NPSynonyms
import Algebra.Additive (C)

newtype Foo a = Foo a

instance (Additive a) => Algebra.Additive.C (Foo a) where ...

So instead of making Additive a type synonym with kind Constraint, what I'd really like is to define a typeclass synonym for the typeclass Algebra.Additive.C. Is there any way to do this in GHC 7.8, or is there any sane alternative?

1
Let's be specific. Only Henning Thielemann names all of his types T and all of his classes C. Everyone else knows it's terrible.Carl
Does he know that it's terrible? I can try to convince him...crockeea
Maybe somebody should just fork numeric-prelude to fix the namesGabriel Gonzalez
It also doesn't display right on Hackage and I'd be surprised if many people would like instance lists that look like this: hackage.haskell.org/package/numeric-prelude-0.4.0.3/docs/…David Young
@DavidYoung Those instances are precisely what I mean about making the documentation unreadable. It is very frustrating to have to hover over hyperlinks and look at the address to read a constraint.crockeea

1 Answers

6
votes

you have to fully qualify

No, not fully qualify. Consider:

import qualified Algebra.Additive as Add

myadd :: Add.C a => a -> a -> a

That looks fairly readable to me.

EDIT:

Also consider making a superclass and treating that as an alias:

class (Add.C a, Ring.C a) => Num a where
instance Num Int
instance Num Word