gpt4 book ai didi

haskell - 将 DeriveGeneric 用于参数化类型

转载 作者:行者123 更新时间:2023-12-02 09:15:11 24 4
gpt4 key购买 nike

我想为我的参数化类型使用自动化的 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)

关于haskell - 将 DeriveGeneric 用于参数化类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47890435/

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