我想写一些类似的东西:
{-# 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 []
Run Code Online (Sandbox Code Playgroud)
意味着f a实例化Rowsif finstanti Foldable和f ainstantiate Show.当我运行ghc时,我得到:
Constraint is no smaller than the instance head
in the constraint: Show (f a)
(Use -XUndecidableInstances to permit this)
In the …Run Code Online (Sandbox Code Playgroud) haskell ×1