【发布时间】:2015-09-13 19:26:24
【问题描述】:
我在 Elm 中编写一个涉及信号的简单 if-then 语句时遇到了困难。
如果条件本身是Signal 类型怎么办?我想更改 Elm 网站上的 Mouse Down 示例:
import Graphics.Element exposing (..)
import Mouse
main : Signal Element
main =
Signal.map show Mouse.isDown
根据鼠标是向上还是向下,它会显示 True 或 False。如果我想让它说“向上”或“向下”怎么办?我的布尔函数可以说:
<!-- language: haskell -->
f : Bool -> String
f x =
if x then "↑" else "↓"
但是当我更改主函数时,我得到类型不匹配。
<!-- language: haskell -->
main : Signal Element
main =
Signal.map show ( f Mouse.isDown)
错误 #1:
The 2nd argument to function `map` has an unexpected type.
10| Signal.map show ( f Mouse.isDown)
As I infer the type of values flowing through your program, I see a conflict
between these two types:
Signal a
String
错误 #2:
The 1st argument to function `f` has an unexpected type.
10| Signal.map show ( f Mouse.isDown)
As I infer the type of values flowing through your program, I see a conflict
between these two types:
Bool
Signal Bool
【问题讨论】:
标签: if-statement frp elm