榆树 - 在记录中更新记录

elm - updating a record within a record

在一条记录中更新一条记录的correct/best方法是什么?

以下尝试:

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 的文字更新吗?

我只需要扩展 Model 定义:

type alias Model =
  { pageView : PageView
  , landingPageModel : { postCode : String }
  }

此外,根据 halfzebra 的评论,Dict 在这里没有相关性 - 只是记录。