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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With