Mic*_*ard 1 haskell types persistent yesod
这是代码,我试着让类型推断找出函数的类型.代码编译时,它在运行时失败.
Ambiguous type variables `b0', `m0' in the constraint:
(PersistBackend b0 m0) arising from a use of `isFree'
Probable fix: add a type signature that fixes these type variable(s)
In the expression: isFree testDay
In an equation for `it': it = isFree testDay
Run Code Online (Sandbox Code Playgroud)
:t isFree
isFree :: PersistBackend b m => C.Day -> b m Bool
>isFree day = do
match <- selectList [TestStartDate ==. day,
TestStatus !=. Passed,
TestStatus !=. Failed] []
if (L.null match) then (liftIO $ return True) else (liftIO $ return False)
Run Code Online (Sandbox Code Playgroud)
ghci的告诉你,它不知道选择哪种类型的表达式b和m.你所要做的就是告诉它,
isFree testDay :: Foo Bar Bool
Run Code Online (Sandbox Code Playgroud)
在实际程序中,这些类型变量通常在使用站点确定,因此您很少需要在那里指定表达式的类型.在ghci提示符下,缺少上下文,因此您经常需要这样做.
不相关,isFree的最后一行会更好 return $ L.null match
| 归档时间: |
|
| 查看次数: |
128 次 |
| 最近记录: |