Haskell Illegal deriving item Generic
Haskell Illegal deriving item Generic
-# LANGUAGE DataKinds #-
-# LANGUAGE DeriveGeneric #-
-# LANGUAGE OverloadedStrings #-
-# LANGUAGE TypeOperators #-
import qualified Data.ByteString.Lazy as BL
import Data.Csv (DefaultOrdered, FromRecord,
ToNamedRecord, ToRecord)
import Data.Generics
import Data.Proxy
import qualified Data.Text as T
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Servant.API
import Servant.Client
import Servant.CSV.Cassava
import System.Environment
data Cata = Cata
csvDate :: String,
csvOpen :: String,
csvHigh :: String,
csvLow :: String,
csvClose :: String,
csvVolume :: String,
csvExDividend :: String,
csvSplitRatio :: String,
csvAdjOpen :: String,
csvAdjHigh :: String,
csvAdjLow :: String,
csvAdjClose :: String,
csvAdjVolume :: String
deriving (Show, Generic)
instance DefaultOrdered Cata
instance FromRecord Cata
instance ToNamedRecord Cata
instance ToRecord Cata
I compile the above code and get the following error: why?
$ stack ghc servantcsv.hs
[1 of 1] Compiling Main ( servantcsv.hs, servantcsv.o )
servantcsv.hs:34:21: error:
• Illegal deriving item ‘Generic’
• In the data declaration for ‘Cata’
|
34 | } deriving (Show, Generic)
| ^^^^^^^
GHC Version: ghc-8.4.3
ghc-8.4.3
1 Answer
1
You want to import GHC.Generics not Data.Generics. What you have imported does have a type Generic but it isn't a class:
GHC.Generics
Data.Generics
Generic
type Generic c = forall a. Data a => a -> c a
Certainly that can't be part of a "deriving" clause.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.