`String' 应用于太多类型参数 [英] `String' is applied to too many type arguments

查看:33
本文介绍了`String' 应用于太多类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚学习 Haskell,我试图编写一个简单的程序来消除 String 中的前 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 给了我这个错误,我不知道为什么:

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 是一种类型,而不是类型类,因此您可以(必须)在类型签名中按原样使用它.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆