Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

haskell - `String' is applied to too many type arguments

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
question from:https://stackoverflow.com/questions/12018959/string-is-applied-to-too-many-type-arguments

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...