作者:从妖妖 | 来源:互联网 | 2022-10-17 17:33
1> Chad Gilbert..:
问题是这种Just launch
情况需要导致a,List (Html msg)
但是代码会导致返回不同的类型。
使用时List.map (\x -> x)
,它本质上是无操作的。您正在遍历a List (Maybe Launch)
并返回相同的东西。我建议创建另一个带有Maybe Launch
值的函数并将其用作映射函数。例如:
displayLaunch : Maybe Launch -> Html Msg
displayLaunch launch =
case launch of
Nothing -> text "No launch"
Just l -> text (Debug.toString l)
现在,您可以将其插入到映射功能中:
Just launch ->
launch
|> List.map displayLaunch
|> ul []
但是,哎呀!现在,您将收到一个新错误,指示:
The 2nd branch is:
Html Msg
But all the previous branches result in:
List (Html msg)
这里的问题是我们现在ul
从Just launch
分支返回a ,并且我们需要返回html列表。您可以List.singleton
用来创建仅包含一项的列表:
The 2nd branch is:
Html Msg
But all the previous branches result in:
List (Html msg)