I want to use automated DeriveGeneric for my parameterized type. I get error. I want to decode a yaml file ino FromJSON type.
{-# 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
Line EPSG * raises error. How should I fix it?
Your definition of EPSG needs to derive generic as well, and then you need to constrain your instance to have a FromJSON instance for a as well.
data EPSG a = EPSG { epsg3857 :: a } deriving Generic
...
instance FromJSON a => FromJSON (EPSG a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With