2017-04-19 21 views
0

我有一個模型:更新功能結合型模式榆樹

type Model 
    = InitialScreen 
    | ErrorScreen Http.Error 
    | List NormalRegion 

和更新功能:

update : Msg -> a -> (Model, Cmd msg) 
update msg model = 
    case msg of 
     FetchFail e -> 
      (ErrorScreen e, Cmd.none) 

     ShowRegions dto -> 
      (GeographiesDecoder.toNormalRegions dto.regions dto.countries, Cmd.none) 

     HoverRegion r -> 
      (model, Cmd.none) 

其中toNormalRegions是

toNormalRegions : List Region -> List Country -> List NormalRegion 

編譯器上更新FN拋出錯誤:

The 1st and 2nd branches of this `case` produce different types of values. - The 1st branch has this type: 

    (Model, Cmd msg) 

But the 2nd is: 

    (List NormalRegion, Cmd msg) 

有沒有辦法將List轉換爲Model?

+0

有關定義爲'列表NormalRegion'一個'型alias'什麼? – pietro909

回答

1

您有一個名爲ListModel類型的構造函數,它與內置的List類型衝突。我懷疑你實際上是在嘗試使用一個實際的區域列表,但這並不代表你所編碼的內容。

我想你會定義一個非重疊的構造得到更好的服務:

type Model 
    = InitialScreen 
    | ErrorScreen Http.Error  
    | Regions (List NormalRegion)