2016-05-02 20 views
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更新ではないでしょうか?

+1

この質問は辞書とは関係ありません。編集してください。 – halfzebra

+1

ありがとう、それは完了しました – category

+2

これはElmの 'lens'ライブラリですが、健康に関する警告に注意してください - 実際には使用したことはありませんhttp://package.elm-lang.org/packages/evancz/focus/2.0.0/ –

答えて

0

私は単にModel定義を拡張するために必要な:

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

また、halfzebraさんのコメントどおり、Dictの者は、ここには関連性がない - レコードだけ。

関連する問題