gpt4 book ai didi

elm - 如何在 Elm 中返回元素列表

转载 作者:行者123 更新时间:2023-12-02 21:10:49 26 4
gpt4 key购买 nike

我正在尝试从 ELM 中的简单数组构建元素列表。预期结果实际上只是一个元素列表,其中 1 作为第一项,2 作为第二项,依此类推。

import Html exposing (..)
import Html.Attributes exposing (class, id)
import List exposing (map)

theArray = [1,2,3,4,5,6]

createListItem item =
li [] [ text (toString item)]

buildList collection =
map createListItem collection

builtList = ul [] [(buildList theArray)]

main =
builtList

但是我在第十三行不断收到编译器错误。我尝试过将 map 元素注释为 html,但我不知道应该做什么。

The 2nd argument to function `ul` is causing a mismatch.

*13| builtList = ul [] [(buildList theArray)]*

Function `ul` is expecting the 2nd argument to be:

List VirtualDom.Node

But it is:

List (List Html)

最佳答案

buildList 已返回 List Html 类型的值,因此您不需要将 (buildList theArray) 括起来。将第 13 行更改为:

builtList = ul [] (buildList theArray)

关于elm - 如何在 Elm 中返回元素列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36723877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com