如何构建用于传递给 purescript 的 `Thermite.focus` 的镜头?

How do a build a lens for passing to purescript's `Thermite.focus`?

我正在关注有关设置任务列表的各种 Thermite 教程。唯一有很多解释的教程也已经过时了,所以我正在修改它以适应当前的 Thermite。但是,我有一个调用无法使数据类型匹配。

import Optic.Lens (lens)
import Optic.Prism (prism)
import Optic.Types (Prism', Lens')
import Thermite as T

_TaskAction :: Prism' TaskListAction (Tuple Int TaskAction)
_TaskAction = ...

_tasks :: Lens' TaskListState (L.List TaskState)
_tasks = lens _.tasks (_ { tasks = _ })

taskList :: T.Spec _ TaskListState _ TaskListAction
taskList = T.focus _tasks _TaskAction taskSpec

但是,这给了我一条错误消息:

  Could not match type

    p0

  with type

    Function

while trying to match type p0 t1
  with type Function             
              (List              
                 { text :: String
                 }               
              )                  
while checking that expression _tasks
  has type p0 t1 t1 -> p0 t2 t2
in value declaration taskList

where p0 is a rigid type variable
        bound at line 213, column 20 - line 213, column 26
      t1 is an unknown type
      t2 is an unknown type

错误信息是专门说我传递给T.focus_tasks参数。但我不知道错误试图告诉我什么。我也知道 T.focus 的类型签名是...

focus :: forall eff props state2 state1 action1 action2.
         Lens' state2 state1
      -> Prism' action2 action1
      -> Spec eff state1 props action1
      -> Spec eff state2 props action2

所以第一个参数是镜头

更令人沮丧的是,我检查了更现代(但更大且更难理解)的示例代码,它显示了与我在这里完全相同的 _tasks 定义。

那么,这条错误消息是什么意思,我需要做什么来修复它?

您正在导入 Optic.Lens 的事实表明您在这里使用了错误的镜头库。 purescript-lens 提供传统的 van-Laarhoven 镜头(如 Haskell 的 lens 库),但 Thermite 使用 profunctor-lenses 库。