svenningsson
svenningsson

Reputation: 4049

Higher kinded empty constraint

I want to have an empty constraint at a higher kind.

Suppose I have the following class:

class Category k where
  type Obj k :: * -> Constraint
  id  :: Obj k a => a `k` a
  (.) :: (Obj k a, Obj k b, Obj k c) => b `k` c -> a `k` b -> a `k` c

Now I want to make an instance for functions such that it doesn't constrain the elements in any way. What do I give as an instance for Obj?

instance Category (->) where
  type Obj (->) = ?
  id    = \a -> a
  f . g = \a -> f (g a)

Upvotes: 2

Views: 58

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153102

You'll need to give it an explicit additional argument in the class declaration.

class Category k where
  type Obj k a :: Constraint

Then it's easy to define the instances using the lower-kinded () empty constraint.

instance Category (->) where
  type Obj (->) a = ()

Upvotes: 4

Related Questions