类型签名“也许”不喜欢“Just [Event]”

时间:2010-05-24 08:56:12

标签: haskell types

我还在学习Haskell,需要帮助进行类型推断!

使用包SDL和Yampa 我从FRP.Yampa.reactimate获得以下类型签名:

(Bool -> IO (DTime, Maybe a))

我希望将其用于:

myInput :: Bool -> IO (DTime, Maybe [SDL.Event])
myInput isBlocking = do
    event <- SDL.pollEvent
    return (1, Just [event])
...
reactimate myInit myInput myOutput mySF

但它说

Couldn't match expected type `()'
       against inferred type `[SDL.Event]'
  Expected type: IO (DTime, Maybe ())
  Inferred type: IO (DTime, Maybe [SDL.Event])
In the second argument of `reactimate', namely `input'
In the expression: reactimate initialize input output process

我认为Maybe a允许我使用任何内容,甚至是SDL.Event列表? 当类型签名实际为Maybe ()时,为什么期望Maybe a? 为什么它需要一个空元组,或一个不带参数的函数,或者()应该是什么?

1 个答案:

答案 0 :(得分:8)

完整的type signature of reactimate

IO a                               -- # myInit
 -> (Bool -> IO (DTime, Maybe a))  -- # myInput
 -> (Bool -> b -> IO Bool)         -- # myOutput
 -> SF a b                         -- # mySF
 -> IO ()

相同的ab必须匹配,这意味着如果您的myInput类型为Bool -> IO (DTime, Maybe [SDL.Event]),则所有其他a也必须为{{1} }}。因此,要匹配类型,您需要确保

[SDL.Event]

BTW, myInit :: IO [SDL.Event] -- # **not** IO (). mySF :: SF [SDL.Event] b unit type

相关问题