Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top