I need a function which takes an arbitrary number of arguments (All of the same type), does something whith them and afterwards gives a result back. A list of arguments is impracticable in my specific case.
As I looked through the haskell libs, there is the function printf
from module Text.Printf
, which uses a similar trick. Poorly I couldn't understand that magic by looking at the source.
Can somebody explain how to archieve this or knows some webpage/paper/whatever, where can I find a good description for this?
Reason:
The reason is really easy going. For school (computer science class), we should write a module which is able to "record" a mathematical expression and express it as a string (Via writing an instance of Num/Real/etc for an own datatype) and can perform various operations on it.
This datatype contains a special constructor for a variable, which may be replaced by a value or whatever by a specified function. One of the goals is to write a function, which takes such an expression, the variables as pairs of type (Char,Rational)
and calculates the result of the expression. We should look, how to express the goal of the function best. (My idea: The function returns another function which takes exactly as many arguments as vars are defined in the function - seems to be impossible).