Frage

Why can't I derive Show here?

{-# LANGUAGE ExistentialQuantification #-}
data Obj = forall a. (Show a) => Item_Obj {get :: a, rest :: Obj} | No_Obj deriving Show

xs :: Obj
xs = Item_Obj 1 $ Item_Obj "foo" $ Item_Obj 'c' $ No_Obj

main :: IO ()
main = putStrLn . show $ xs
War es hilfreich?

Lösung

Such kind of context in not allowed in haskell-98 datatypes. Read this

Ofcourse you can write standalone instance by using StandaloneDeriving extension and let ghc do rest of the hardwork.

deriving instance Show Obj

Andere Tipps

Basically because GHC's head explodes when you try that. In other words, it simply hasn't been taught how to derive instances for existential types. Wait for a few version numbers to pass and then try again.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top