0

The map function works fine on really easy functions that take no arguments like *7 to every element in a list of Ints.

But say I made a custom function that takes a Char, String and Int and then returns a Char and I wanted to apply this function to a list of Chars i.e. a String to get a String back after applying the other function to each Char? When I try this all I get is error messages?

11
  • You mean something like this: map (\x -> f x "string" 10) "another string" ? Commented Oct 13, 2013 at 12:17
  • What is the expected result of applying your function to a single Char? Commented Oct 13, 2013 at 12:18
  • map doesn't work on functions that take no arguments, but on functions that take one argument. The type of map is: map::(a -> b) -> [a] -> [b]. (a -> b) is a function that takes a value of type a to return another of type b. Commented Oct 13, 2013 at 12:19
  • @S.R.I I don't care if it's 0 or 1 argument, I know what it does! All I want to know is how I can map a function that takes many arguments to a list. Commented Oct 13, 2013 at 13:00
  • @Eddie, can you refine your question, then? In particular, answer n.m's question - or IOW, can you take partial function application? Commented Oct 13, 2013 at 13:02

1 Answer 1

1

Put your Char argument to the last position:

foo :: String -> Int -> Char -> Char
foo str num c = c

bar = map (foo str num)

But we really need some more information from your side to help you better. Can you add the code you tried to write to your question?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.