带映射的 Haskell 高阶函数
test::Int->(Int-> Char)->Char
test n f = f(n)
DD::Int->Char
DD a | a==1 = '1'
test 是一个当前返回 char 值的高阶函数,我需要返回一个 String
作为 test::Int->(Int-> Char )->String
我将函数体更改为
test::Int->(Int-> Char)->String
test n f = map f(n)
Error
Type error in application
*** Expression : map f n
*** Term : n
*** Type : Int
*** Does not match : [a]
我如何将此函数应用于带有 map 的字符串?我哪里错了?
test::Int->(Int-> Char)->Char
test n f = f(n)
DD::Int->Char
DD a | a==1 = '1'
test which is a higher order function currently returning a char value , i required to return a String
as test::Int->(Int-> Char)->String
i changed to function body as
test::Int->(Int-> Char)->String
test n f = map f(n)
Error
Type error in application
*** Expression : map f n
*** Term : n
*** Type : Int
*** Does not match : [a]
How can i apply this function to a string with map ? where i went wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于字符串只是一个字符列表,因此尝试返回一个字符列表:
顺便说一句,在 Haskell 中,如果不是真正需要的话,我们通常不使用括号。
Since a string is simply a list of chars, try out to return a list of chars:
BTW, in Haskell we usually don't use paranthesis if they are not really needed.