-1
test::Int->(Int-> Char)->Char
test n f =  f(n)

DD::Int->Char
DD a | a==1 = '1'

测试这是一个高阶函数,当前返回一个char值,我需要返回一个Stringas test::Int->(Int-> Char)->String

我改为功能体

test::Int->(Int-> Char)->String
test n f =  map f(n)

错误

Type error in application
*** Expression     : map f n
*** Term           : n
*** Type           : Int
*** Does not match : [a]

如何将此函数应用于带有 map 的字符串?我哪里出错了?

4

1 回答 1

3

由于字符串只是一个字符列表,请尝试返回一个字符列表:

test n f =  [f n]

顺便说一句,在 Haskell 中,如果不是真的需要,我们通常不会使用括号。

于 2011-06-11T14:26:50.163 回答