I understand there are no "positional" arguments in the sense that all functions take only a single variable and return a function to operate on the remaining arguments, but here's what I mean I want to do:
Starting with some function I'm using to format lists with a prepended item, a separator, and a closing item.
Prelude> formatList start end sep xs = start ++ (intercalate . separator ( map show xs )) ++ end
Works like this:
Prelude Data.List> formatList "(" ")" "," [1..10]
"(1,2,3,4,5,6,7,8,9,10)"
Cool, same idea can be used for xml tags:
Prelude Data.List> formatList "<meow>" "</meow>" "" [1..10]
"<meow>12345678910</meow>"
In the spirit of reusing functions and terseness, let's also make it so we don't have to type the redundant part of the meow tag by making a function to produce the open and close from just the word "tag."
Prelude Data.List> tagger tag item = "<" ++ tag ++ ">" ++ item ++ "</" ++ tag ++ ">"
Prelude Data.List> tagger "div" "contents"
"<div>contents</div>"
So now make some tag-maker that will return a start and end I can make the second argument to my formatList function:
Prelude Data.List> tagMaker tag = ("<" ++ tag ++ ">", "</" ++ tag ++ ">")
Looks good:
Prelude Data.List> tagMaker "div"
("<div>","</div>")
Now try it. Actual behavior:
Prelude Data.List> formatList (tagMaker "div") "" [1..10]
<interactive>:49:13: error:
• Couldn't match expected type ‘[Char]’
with actual type ‘([Char], [Char])’
• In the first argument of ‘formatList’, namely ‘(tagMaker "div")’
In the expression: formatList (tagMaker "div") "" [1 .. 10]
In an equation for ‘it’:
it = formatList (tagMaker "div") "" [1 .. 10]
Desired behavior:
formatList (tagMaker "div") "" [1..10]
"<div>12345678910</div>
What's the right way to make the tagMaker function be able to sub in for a function that expects to take its first value, then its second value? If this is completely non-idiomatic, what's the right idiom?