haskell错误。请指导我如何解决此问题

时间:2019-12-30 02:50:53

标签: haskell

import Data.List
step :: [Int] -> String -> [Int] 
step (x:y:ys) "*" = (x * y):ys
step (x:y:ys) "+" = (x + y):ys
step (x:y:ys) "-" = (y - x):ys
step xs numberString = read numberString:xs

下面是我一直得到的我的代码和错误,请提供任何帮助。谢谢。

*Main> step [2+6]: this is what i put into my terminal

<interactive>:5:1: error:
    • No instance for (Show (String -> [Int]))
        arising from a use of ‘print’
        (maybe you haven't applied a function to enough arguments?)
    • In a stmt of an interactive GHCi command: print it
*Main> 

1 个答案:

答案 0 :(得分:0)

使用@-moz-document url-prefix() { a.soft { background-color: #ddd; box-shadow: -10px -10px 20px 0 #E6E6E6, 10px 10px 20px 0 #ABABAB, inset 10px 10px 20px 0 #E6E6E6, inset -10px -10px 20px 0 #ABABAB; color: #888; } } 只能部分应用函数,因此返回值不是列表step [2+6],而是函数[Int]。 (部分应用函数意味着仅提供所需的一些参数,然后取回包含其余参数的函数。是的,您可以在Haskell中做到这一点!)

您看到的错误只会在终端中出现,因为ghci尝试将String -> [Int]应用于每个语句,但是函数无法显示。

因此,如果您要完全应用函数以实际运行它,则需要提供其所需的所有参数,即

show