2017-04-19 41 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)