我想为我的参数化类型使用自动化的 DeriveGeneric。我得到错误。我想解码一个 FromJSON 类型的 yaml 文件。
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
import Web.Scotty
import Data.ByteString.Char8 (pack, unpack)
import Data.ByteString.Lazy (toStrict, fromStrict)
import Data.List
import Data.Yaml
import GHC.Generics
data EPSG a = EPSG { epsg3857 :: a }
data Resolution = Resolution { max :: Int, items :: [Double]}
data Config = Config { minX :: EPSG Double, minY :: EPSG Double, maxX :: EPSG Double, maxY :: EPSG Double
, resolution :: EPSG Resolution
, metersPerUnit :: EPSG Double
, pixelSize :: EPSG Double
, scaleNames :: EPSG [String]
, tileWidth :: EPSG Double
, tileHeight :: EPSG Double
, subdirBit :: EPSG [Int]
, subdirShiftBit :: EPSG [Int]
, subdirNumSize :: EPSG [Int]
, fileNameNumSize :: EPSG [Int] } deriving Generic
instance FromJSON EPSG *
instance FromJSON Resolution
instance FromJSON Config
行 EPSG * 引发错误。我该如何解决?
最佳答案
您对 EPSG
的定义也需要派生泛型,然后您需要将您的实例约束为具有 a
的 FromJSON
实例
data EPSG a = EPSG { epsg3857 :: a } deriving Generic
...
instance FromJSON a => FromJSON (EPSG a)
关于haskell - 将 DeriveGeneric 用于参数化类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47890435/