我有卤素成分的状态,包括这样的镜头:
import Optic.Core (Lens', lens)
type State =
{ userName :: String
, password :: String
, formError :: String
}
_userName :: Lens' State String
_userName = lens _.userName (\r str -> r { userName = str })
我想修改同一组件的eval函数中的状态,如下所示:
eval :: forall eff.
Query ~> ParentDSL State Query UserNameField.Query Slot Void (Aff (console :: CONSOLE , ajax :: AJAX | eff))
eval = case _ of
HandleInput userName next -> do
-- this code causes trouble:
_userName .= userName
-- while this code works:
-- modify (set _userName userName)
pure next
但是,我收到错误消息:
Could not match type
{ userName :: String
, password :: String
, formError :: String
}
with type
( userName :: String
, password :: String
, formError :: String
)
while trying to match type t3
{ userName :: String
, password :: String
, formError :: String
}
with type t2
while checking that expression _userName
has type (t0 -> t1) -> t2 -> t2
in value declaration eval
where t1 is an unknown type
t0 is an unknown type
t2 is an unknown type
t3 is an unknown type
[TypesDoNotUnify]
请注意{
和(
之间的差异(花了一些时间)。我甚至不知道后一种类型实际意味着什么,我不知道为什么这个错误是由基于MonadState
的镜头引入的。
答案 0 :(得分:2)
神秘解决了:我无意中混了两个包
purescript-lens
和purescript-profunctor-lenses
。我的镜头来自前者,而assign
函数(.=
)仅出现在后者中,后者显然是作为一些隐含的子顺从而安装的。