gpt4 book ai didi

Haskell 非法派生项泛型

转载 作者:行者123 更新时间:2023-12-02 11:18:38 25 4
gpt4 key购买 nike

{-# 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

我编译上面的代码并得到以下错误:为什么?

$ 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 版本:ghc-8.4.3

最佳答案

您想要导入GHC.Generics而不是Data.Generics。您导入的内容确实具有 Generic 类型,但它不是一个类:

type Generic c = forall a. Data a => a -> c a

当然,这不能成为“派生”子句的一部分。

关于Haskell 非法派生项泛型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52226765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com