haskell - 使用 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'
?
解决方案
也许是这样的:
data Config where
request :: Request -> Config
newtype Request = Request (HashMap Text URI)
HashMap
有以下实例:FromJSON v => FromJSON (HashMap Text v)
因此您可以轻松地使用和类似地FromJSON
为这种类型定义.-XGeneralizedNewtypeDeriving
ToJSON
推荐阅读
- mysql - 失去对带有表连接的 INFORMATION_SCHEMA.COLUMNS 表的查询
- c - 不使用双指针交换字符串
- azure - 微软认知服务人脸 API
- javascript - 将无操作或空处理程序绑定到 Vue 事件处理程序?
- ios - 如何使用 AlertBox 和 CoreData 从两个 UITableViewCell 传递数据?
- sql - 使用 join 语句创建 case 表达式;甲骨文
- telegram - 如何删除电报组
- theory - 理解 Coq 中“有根据的”证明
- gradle-kotlin-dsl - 将 sourceDir 添加到 java sourceSet
- jenkins - 如何在 Jenkins 中使用量角器?