2
我有一個狀態鹵素成分,包括像這樣的鏡頭:如何解決此Purescript錯誤:無法與{...}匹配(...)?
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
的透鏡引入的。