How to fix this Purescript error: Could not match {...} with (...)?

How to fix this Purescript error: Could not match {...} with (...)?

我有一个卤素组件的状态,包括这样的镜头:

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 的镜头会引入此错误。

谜底已解:我无意中把两个包混在一起了

purescript-lenspurescript-profunctor-lenses。我的镜头来自前者,assign 函数 (.=) 仅出现在后者中,后者显然是作为某种隐式从属项安装的。