`String'被应用于太多的类型参数 [英] `String' is applied to too many type arguments
本文介绍了`String'被应用于太多的类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是在学习Haskell,我正在编写一个简单的程序来消除 String
中的前n个字符。这是我得到的:
cutString ::(Num n,String str)=> n - > str - > str
cutString n str =
的情况n 0 - > tail str
n - >但是,GHC给了我这个错误,但我可以'''''' t找出原因:
`String'应用于太多的类型参数
在`cutString的类型签名':
cutString ::(Num n,String str)=> n - > str - > str
解决方案 String
是一个类型,而不是一个类型类型,所以你可以(必须)直接在类型签名中使用它。
cutString :: Num n => n - >字符串 - >字符串
I'm just learning Haskell and I was trying to write a simple program to eliminate the first n characters from a String
. This is what I got:
cutString :: (Num n, String str) => n -> str -> str
cutString n str = case n of
0 -> tail str
n -> cutString (n-1) (tail str)
GHC gives me this error though, and I can't figure out why:
`String' is applied to too many type arguments
In the type signature for `cutString':
cutString :: (Num n, String str) => n -> str -> str
解决方案 String
is a type, not a typeclass, so you can (must) just use it as-is in the type signature.
cutString :: Num n => n -> String -> String
这篇关于`String'被应用于太多的类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文