以下代码:
import Svg exposing (..)
import Window exposing (..)
init_size : Model msg -> Size
init_size _ =
{ width = 800, height = 600 }
type alias Model msg =
{ extra_size : Int
, size : Size
, child_elements : List (Svg msg)
}
init_renderSpace : Model msg
init_renderSpace model =
{ extra_size = 40
, size = init_size model
, child_elements = []
}
,产生一条我无法理解的奇怪错误消息。有谁知道我做错了什么?
这是错误消息:
-- TYPE MISMATCH ----------------------------------------------------- space.elm
The definition of `init_renderSpace` does not match its type annotation.
21| init_renderSpace : Model msg
22| init_renderSpace model =
23|> { extra_size = 40
24|> , size = init_size model
25|> , child_elements = []
26|> }
The type annotation for `init_renderSpace` says it is a:
Model msg
But the definition (shown above) is a:
Model msg
-> { child_elements : List (Svg msg), extra_size : Int, size : Size }
Hint: It looks like a function needs 1 more argument.
Hint: The type annotation says there are NO arguments, but there is 1 argument
named in the definition. It is best practice for each argument in the type to
correspond to a named argument in the definition, so try that first!
基本上我尝试创建一个记录,该记录的参数基本上是svg节点列表。当我尝试使用空列表初始化模型时,我收到错误。
答案 0 :(得分:3)
错误消息表示您init_renderSpace
的类型定义为Model msg
,但其实现为Model msg -> Model msg
。换句话说,你是说init_renderSpace
是一个模型,但它实际上是一个获取模型并返回模型的函数。
因为您没有在init_size
中使用任何参数,我会从init_size
和init_renderSpace
删除参数:
init_size : Size
init_size =
{ width = 800, height = 600 }
init_renderSpace : Model msg
init_renderSpace =
{ extra_size = 40
, size = init_size
, child_elements = []
}