Skip to content

Explicit type signature for type classes fails

GHC 8.0.1: Consider the indexed classes:

class IxFunctor f where
  imap :: (a -> b) -> f j k a -> f j k b

class IxFunctor m => IxPointed m where
  ireturn :: a -> m i i a

class IxPointed m => IxApplicative m where
  iap :: m i j (a -> b) -> m j k a -> m i k b

class IxFunctor w => IxCopointed w where
  iextract :: w i i a -> a

class IxApplicative m => IxMonad m where
  ibind :: (a -> m j k b) -> m i j a -> m i k b

class IxMonad m => IxMonadFree f m | m -> f where
  iwrap :: f i j (m j k a) -> m i k a

GHCi gives their kinds:

IxFunctor     :: (k -> i -> * -> *)                       -> Constraint
IxPointed     :: (k -> k -> * -> *)                       -> Constraint
IxApplicative :: (k -> k -> * -> *)                       -> Constraint
IxCopointed   :: (k -> k -> * -> *)                       -> Constraint
IxMonad       :: (k -> k -> * -> *)                       -> Constraint
IxMonadFree   :: (k -> k -> * -> *) -> (k -> k -> * -> *) -> Constraint

so I attempt to make them explicit:

type IxFunct i = i -> i -> Type -> Type

class IxFunctor (f :: IxFunct i) where
  imap :: (a -> b) -> f j k a -> f j k b                                                               

Works fine, but if I add it to any of the others it fails:

-- tZRa.hs:15:17: error: … 
--     • Expected kind ‘i’, but ‘i’ has kind ‘*’
--     • In the first argument of ‘w’, namely ‘i’
--       In the type signature:
--         iextract :: w i i a -> a
--       In the class declaration for ‘IxCopointed’
-- Compilation failed.
class IxFunctor w => IxCopointed (w :: IxFunct i) where
  iextract :: w i i a -> a

-- ...
class IxMonad m => IxMonadFree (f :: IxFunct i) (m :: IxFunct i) | m -> f where
  iwrap :: f i j (m j k a) -> m i k a
Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information