解构榆树​​中的列表列表

Destructuring a list of lists in elm

我正在尝试解构 elm (0.18) 中的列表列表。这是函数调用:

  twoColumns
       [ [ Widget1, Widget2 ]
       , [ Widget3, Widget4 ]
       ]

调用这个函数:

twoColumns : List List Widget -> Html Msg
twoColumns listoflists =
   case listoflists of
      listLeft :: listRight :: _ ->
         div []
             [ div [ class "col-md-6" ] (parsingOperation listLeft)
             , div [ class "col-md-6" ] (parsingOperation listRight)
             ]
      _ ->
         div [] [ text "Error" ]

(假设 parseOptions 接受 List Widget 作为参数。)

这似乎是简单的解构,但我收到了这个错误:

Tag `::` is causing problems in this pattern match.

71|             listLeft :: listRight :: _ ->
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
The pattern matches things of type:

    List a

But the values it will actually be trying to match are:

    List List Widget

有什么想法吗?

注意 当我尝试使用模式 (listLeft::listRight::_) 时,elm-format 将其恢复为上面的模式。

List List Widget 应该是 List (List Widget)。因为 List List Widget 意味着完全不同(而且毫无意义)的事情。然而,这很有趣,为什么 Elm 编译器甚至允许 List List Widget。我猜这是编译器的一个错误。