elm - 更新记录中的记录

时间:2016-05-02 19:30:35

标签: updates record elm

更新记录中记录的正确/最佳方法是什么?

以下尝试:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
      <remove name="ChartImageHandler"/>
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </handlers>
  </system.webServer>

发出此错误:

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

1 个答案:

答案 0 :(得分:0)

我只需要扩展Model定义:

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

另外,根据halfzebra的评论,Dict与此无关 - 只是记录。