gpt4 book ai didi

haskell - `String' 应用于太多类型参数

转载 作者:行者123 更新时间:2023-12-02 06:40:23 25 4
gpt4 key购买 nike

我刚刚学习 Haskell,我正在尝试编写一个简单的程序来消除 String 中的前 n 个字符。这就是我得到的:

cutString :: (Num n, String str) => n -> str -> str

cutString n str = case n of
0 -> tail str
n -> cutString (n-1) (tail str)

GHC 给了我这个错误,但我不明白为什么:

`String' is applied to too many type arguments
In the type signature for `cutString':
cutString :: (Num n, String str) => n -> str -> str

最佳答案

String 是一种类型,而不是类型类,因此您可以(必须)在类型签名中按原样使用它。

cutString :: Num n => n -> String -> String

关于haskell - `String' 应用于太多类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12018959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com