开发者

Haskell higher order function with map [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow开发者_如何学编程 situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.
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 ?


Since a string is simply a list of chars, try out to return a list of chars:

test n f =  [f n]

BTW, in Haskell we usually don't use paranthesis if they are not really needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜