What does “Contrast no less than the head of an instance” mean and how to solve it

I would like to write something like:

{-# LANGUAGE FlexibleContexts,FlexibleInstances #-}

import Data.ByteString.Char8 (ByteString,pack)
import Data.Foldable (Foldable)

class (Show a) => Rows a where
    rRepr :: a -> [ByteString]
    rRepr = (:[]) . pack . show

instance (Foldable f,Show (f a)) => Rows (f a) where
    rRepr = const []

means that f acreates an instance Rowsif it fcreates an instance Foldableand f acreates an instance Show. When I start ghc, I get:

Constraint is no smaller than the instance head
  in the constraint: Show (f a)
(Use -XUndecidableInstances to permit this)
In the instance declaration for `Rows (f a)'

I have two questions:

  • what does “less” mean in error and what is the problem?
  • What is the correct way to determine what I want without using UndecidableInstances?
+3
source share
1 answer

: (f a), , Rows. , (f a) Show (f a). , -

 instance Rows (f a) => Show (f a) where ...

, . , , , Haskell , , UndecidableInstances.


Haskell , " " 1 . , .

, , , , . , Agda Coq, , .


, ? - Show class Show1 prelude-extras.

class Show1 f where ...
show1 :: (Show1 f, Show a) => f a -> String  -- not an instance definition!

instance (Foldable f, Show1 f, Show a) => Rows (f a) where ..., . .

defRRepr :: Show a => a -> [ByteString]
defRRepr = (:[]) . pack . show

Show .


newtype, Haskell , "" .

instance (Foldable f, Show (f a)) => Rows (FoldableRow f a) where
    rRepr = const [] . unFR

newtype FoldableRow f a = FR { unFR :: f a } deriving (Show)
+8

All Articles