这是Defining variables inside a function Haskell
提出的问题的重新设定我有一个函数,其开头看起来像这样:
recursiveLs :: FilePath -> IO [FilePath]
recursiveLs dir =
do
folderExists <- doesDirectoryExist dir
if folderExists
then ...
问题是,在动作中分配folderExists
之前,如何明确声明{{1}}的类型?
答案 0 :(得分:7)
好吧,让我们尝试在ghci
:
> (a :: Integer) <- return 10
<interactive>:2:7:
Illegal type signature: `Integer'
Perhaps you intended to use -XScopedTypeVariables
In a pattern type-signature
所以,我们应该启用该编译指示。
> :set -XScopedTypeVariables
再试一次
> (a :: Integer) <- return 10
a :: Integer
现在我们a
等于10
,即Integer
:
> a
10
it :: Integer
此外,我相信您忘记了=
函数中的recursiveLs
,应该有类似recursiveLs dir = do ...