1
我想用purescript-lens更新嵌套記錄的屬性。然而,當我撰寫的鏡頭獲得的財產,我得到以下類型的錯誤:purescript-鏡頭組成類型錯誤
Warning: Error at src/Main.purs line 150, column 38 - line 152, column 3:
Error in declaration performAction
Cannot unify { description :: u24500 | u24501 } with Main.Item. Use --force to continue.
我是比較新的鏡頭和purescript,因此它可能是一些簡單而明顯的。
產生這個錯誤如下(是的,它是基於purescript - 鋁熱-todomvc)的相關代碼:
data Action
= NewItem String String String String String
| RemoveItem Index
| SetEditText String
| DoNothing
data Item = Item
{ description :: String
, keywords :: String
, link_title :: String
, profile :: String
, title :: String
}
data State = State
{ item :: Item
, editText :: String
}
_State :: LensP State { item :: _, editText :: _ }
_State f (State st) = State <$> f st
item :: forall r. LensP { item :: _ | r } _
item f st = f st.item <#> \i -> st { item = i }
editText :: forall r. LensP { editText :: _ | r } _
editText f st = f st.editText <#> \i -> st { editText = i }
itemDescription :: forall r. LensP { description :: _ | r } _
itemDescription f it = f it.description <#> \d -> it { description = d }
performAction :: T.PerformAction _ Action (T.Action _ State)
performAction _ action = T.modifyState (updateState action)
where
updateState :: Action -> State -> State
updateState (NewItem s1 _ _ _ _) = _State .. item .. itemDescription .~ s1
updateState (SetEditText s) = _State .. editText .~ s
updateState DoNothing = id
我試圖更新的屬性是st.item.description和上述錯誤指的是啓動「updateState(的newitem ......」奇怪的是,也有報道爲下一行同樣的錯誤就行了。
就如何解決該類型的錯誤任何想法?
感謝