将 DeriveGeneric 用于参数化类型

Use DeriveGeneric for parameterized type

我想为我的参数化类型使用自动化的 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 的定义也需要派生泛型,然后您需要限制您的实例也具有 aFromJSON 实例。

data EPSG a = EPSG { epsg3857 :: a } deriving Generic

...

instance FromJSON a => FromJSON (EPSG a)