Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deriving show when using ExistentialQuantification extension?

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
like image 369
Vanson Samuel Avatar asked Sep 17 '12 02:09

Vanson Samuel


2 Answers

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
like image 69
Satvik Avatar answered Sep 27 '22 23:09

Satvik


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.

like image 22
ertes Avatar answered Sep 27 '22 22:09

ertes