首页 > 解决方案 > 使用 Haskell 解析嵌套的 yaml

问题描述

如何为以下 yaml 配置定义一种类型:

request: 
  a: "https://google/1"
  b: "https://google/2" 
  c: "https://google/3"

会是这样吗?

data Config = Config { request :: id' } deriving (Show, Generic)

然后再定义id'

标签: haskellyaml

解决方案


也许是这样的:

data Config where
  request :: Request -> Config

newtype Request = Request (HashMap Text URI)

HashMap有以下实例:FromJSON v => FromJSON (HashMap Text v)因此您可以轻松地使用和类似地FromJSON为这种类型定义.-XGeneralizedNewtypeDerivingToJSON


推荐阅读