Why can't I show the show here?

Why can't I get a 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
+5
source share
2 answers

This type of context is not allowed in haskell-98 data types. Read this

Of course, you can write a separate instance using the extension StandaloneDerivingand let ghc do the rest of the work.

deriving instance Show Obj
+8
source

Mostly because the GHC's head explodes when you try to do it. In other words, he was simply not taught to derive instances for existential types. Wait for several version numbers to pass, then try again.

+2
source

All Articles