PureScript嵌套行多态性

3

PureScript实例教程5.9练习1和2

我的解决方案:

type HasCity r s = { address :: { city :: String | r } | s }

livesInLA :: forall r s. HasCity r s -> Boolean
livesInLA { address: { city: "Los Angeles" } } = true
livesInLA _ = false

sameCity :: forall r s t u. HasCity r s -> HasCity t u -> Boolean
sameCity a b = a.address.city == b.address.city

问题: forall r s t u. HasCity r s -> HasCity t u这种写法太糟糕了,能简化一下吗?
1个回答

1
如果您想保留行作为可选字段,那么并不是真的。我唯一能建议的小简化是:
forall r s. HasCity r s -> HasCity r s -> Boolean

但这需要两个参数具有完全相同的结构(同时允许额外的标签),而原始类型仅要求每个记录具有等式测试中使用的字段。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接