2
レコード内のレコードを更新する正しい/最良の方法は何ですか?elm - レコード内のレコードの更新
次の試み:
type alias Model =
{ pageView : PageView
, landingPageModel : Dict
}
--update
update : Action -> Model -> Model
update action model =
case action of
ChangePage pView ->
{ model | pageView = pView }
PostCode pCode ->
let
lPModel =
model.landingPageModel
newlPModel =
{ lPModel | postCode = pCode }
in
{ model | landingPageModel = newlPModel }
このエラーが発生しました:
The type annotation for `update` does not match its definition.
19│ update : Action -> Model -> Model
^^^^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:
Action
-> { ..., landingPageModel : Dict }
-> { ..., landingPageModel : Dict }
But I am inferring that the definition has this type:
Action
-> { ..., landingPageModel : { a | postCode : String } }
-> { ..., landingPageModel : { a | postCode : String } }
これはやや驚くべきことであるが - タイプDict
のリテラルDict
更新ではないでしょうか?
この質問は辞書とは関係ありません。編集してください。 – halfzebra
ありがとう、それは完了しました – category
これはElmの 'lens'ライブラリですが、健康に関する警告に注意してください - 実際には使用したことはありませんhttp://package.elm-lang.org/packages/evancz/focus/2.0.0/ –