我使用自己编写的Toolbox
模块,它编译时没有任何错误或警告。但是,当调用menubar
函数时,控制台会显示"过多的递归"警告。
Toolbox.elm
module Toolbox exposing (..)
import List exposing (head, tail)
import Maybe exposing (withDefault)
import Html exposing (..)
import Html.Attributes exposing (..)
menubar : Html Never
menubar =
div
[ class "relative bg-dark-blue firasans white ttu pa2" ]
[ img
[ src "i/balloon.png"
, width 45
, height 73
]
[]
, ul
[ class "dt absolute bl-l b--white list pa1 ml3 mt2"
, style
[ ( "left", "45px" )
, ( "top", "0" )
, ( "height", "73px" )
]
]
(imgList
[ class "dtc v-mid" ]
[]
[ "i/home.png"
, "i/tutorials.png"
]
)
]
imgList : List (Attribute msg) -> List (Maybe (Attribute msg)) -> List String -> List (Html msg)
imgList attrs events srcs =
case (head events) of
Nothing ->
(li
attrs
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs [] (wdEmpty (tail srcs)))
Just maybe ->
case maybe of
Nothing ->
(li
attrs
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs (wdEmpty (tail events)) (wdEmpty (tail srcs)))
Just event ->
(li
(event :: attrs)
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs (wdEmpty (tail events)) (wdEmpty (tail srcs)))
wdEmpty =
withDefault []
wdEmptyStr =
withDefault ""
答案 0 :(得分:1)
刚开始查看Javascript控制台并看到“过多的递归”警告。
通过以这种方式重写Toolbox.imgList
来修复:
imgList : List (Attribute msg) -> List (Maybe (Attribute msg)) -> List String -> List (Html msg)
imgList attrs events srcs =
case srcs of
[] ->
[]
_ ->
case (head events) of
Nothing ->
(li
attrs
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs [] (wdEmpty (tail srcs)))
Just maybe ->
case maybe of
Nothing ->
(li
attrs
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs (wdEmpty (tail events)) (wdEmpty (tail srcs)))
Just event ->
(li
(event :: attrs)
[ img [ src (wdEmptyStr (head srcs)) ] [] ]
)
:: (imgList attrs (wdEmpty (tail events)) (wdEmpty (tail srcs)))