【发布时间】:2017-07-06 06:14:17
【问题描述】:
对通过示例学习 Purescript 一书中的某些示例有疑问。特别是第 9.3 节中的这段代码:
main :: Eff (canvas :: CANVAS) Unit
main = void $ unsafePartial do
Just canvas <- getCanvasElementById "canvas"
ctx <- getContext2D canvas
setFillStyle "#0000FF" ctx -- this's line 16 referred to in the error message
fillPath ctx $ rect ctx
{ x: 250.0
, y: 250.0
, w: 100.0
, h: 100.0
}
给出以下错误:
在模块 Example.Rectangle 中 在 src\Example\Rectangle.purs 第 16 行,第 3 列 - 第 16 行,第 29 列
类型的结果
Context2D
在 do 表示法块中被隐式丢弃。 您可以使用 _
在应用函数时丢弃 类型丢弃 t0 => 绑定 t1 => t1 t0 -> (t0 -> t1 t2) -> t1 t2 参数 (setFillStyle "#0000FF") ctx 同时推断丢弃的类型 ((setFillStyle "#0000FF") ctx) 在价值声明中主要
其中 t0 是未知类型 t2 是未知类型 t1 是未知类型
更多信息请参见https://github.com/purescript/documentation/blob/master/errors/NoInstanceFound.md,
建议的错误没有帮助,我无法弄清楚“丢弃”究竟是做什么的。我还注意到一个类似的问题,例如,第 8.17 节中的“模拟”功能。如果我尝试使用“_
(这是使用 PSCi 0.11.5)
【问题讨论】:
-
请分享您的代码,而不是图书链接。这不起作用。