【发布时间】:2022-08-17 02:24:55
【问题描述】:
以前我有这种类型:
type Directions =
{ top :: Boolean
, right :: Boolean
, bottom :: Boolean
, left :: Boolean
}
对于这种类型,我有这个功能
empty = { top: false, right: false, bottom: false, left: false}
withLeft = empty { left = true }
我想将Directions 转换为newtype,但我也想使用与withLeft 相同的语法,像这样...
newtype Directions = Directions
{ top :: Boolean
, right :: Boolean
, bottom :: Boolean
, left :: Boolean
}
empty = Directions { top: false, right: false, bottom: false, left: false}
withLeft = empty { left = true }
...但这不起作用。我该怎么做?
-
不是 100% 确定,但我认为您必须手动打开/包装:
withLeft = let Directions empty\' = empty in Directions empty\' { left = true }。 -
@Dogbert 看来您是对的,我通过使用与您的
empty\'相同的默认记录找到了类似的解决方案。
标签: purescript