无法获取 Haskell 中列表的长度

Can't get the length of a list in Haskell

我是 Haskell 的新手,我正在尝试获取函数创建的列表的长度。我收到此错误,但我不明白它的含义:

    * Couldn't match expected type `t1 -> a0' with actual type `Int'
    * The function `length' is applied to two value arguments,
        but its type `(Int -> [String]) -> Int' has only one
      In the first argument of `print', namely `(length strings 1)'
      In a stmt of a 'do' block: print (length strings 1)
  |
9 |     print(length strings 1)
  |           ^^

使用 print (strings 1) 调用该函数有效,所以我不明白为什么我无法获取它的长度。

strings :: Int -> [ String ]
strings 0 = [""] 
strings n = concat ( map (\x -> map (\ tail -> x: tail ) tails ) ['a'.. 'z'])
    where tails = strings (n -1)

main :: Int main = do
    print(length strings 1)

length strings 1 表示您将函数 length 应用于参数 strings1。用其他语言写成length(strings, 1)。但是 1 应该是 strings 的参数,因此您应该改为编写以下内容之一:

print (length (strings 1))
print (length $ strings 1)
print $ length $ strings 1
print . length $ strings 1    -- recommended version
(print . length . strings) 1