【发布时间】:2021-02-18 15:42:22
【问题描述】:
printExclamation :: Int -> IO()
pintExclamation n = do {
n <- getInt;
if n == n;
then return !
}
编译时,我得到“parse error on input `}'”。我不知道为什么。
【问题讨论】:
-
没有
else。此外,!没有返回值的定义,您在do块中同时使用n作为参数和变量。 -
我知道 if n == n 什么都不做,但我想先编译一下,然后才能弄清楚该怎么做
-
在 Haskell 中,
if ... then ... else ...总是有一个else块,因为if ... then ... else ...不是 语句,而是表达式。与(大多数)命令式语言相比,这只是函数应用程序的语法糖,例如,您可以将其替换为ifThenElse。 -
我会在哪里定义输出很多!取决于 n?
-
@Sattoshi7:因为类型是
IO (),所以只能返回一个单位(),不能返回值……
标签: function parsing haskell io return