Wikipedia says: "Metaprogramming is the writing of computer programs with the ability to treat programs as their data." Writing C++ templates to treat Relax NG specifications and literal XML in C++ as input for schema validation would fit that definition.
The following syntax in Haskell causes a parse error in my brain:
contains :: NameClass -> QName -> Bool
I really want it to be contains :: (NameClass, QName) -> Bool
Or even just contains :: NameClass, QName -> Bool
Is it just my problem to get over or do other people have it, or is there syntactic sugar coming to my rescue? contains :: (NameClass, QName) -> Bool
is valid Haskel, and denotes that "contains" is a function that takes a tuple and returns a bool. As a matter of style, Haskellers tend to avoid writing function like this, and prefer to write functions like contains :: NameClass -> (QName -> Bool)
which indicates that "contains" is a function that takes a "NameClass" and returns another function. Because this pattern is so common in Haskell, -> is defined to be right-associative, so the paranthese can be omited. contains :: NameClass -> QName -> Bool
two ways? Like, contains :: (NameClass, QName) -> Bool
And contains :: NameClass -> (QName, Bool)
? What about four types? contains :: Urk -> NameClass -> QName -> Boola -> b -> c -> d always means a -> (b -> (c -> d)).
"->" is right-associative.
f :: A -> B -> C -> D
f a :: B -> C -> D
f a b :: C -> D
f a b c :: D
This is why Haskell's function call syntax seems a bit funny, and the typing syntax (->) seems funny. Every time you apply an argument you get a new object back which represents the result of applying the function. Once you've applied everything to the left of the rightmost type, you have the result.
It's a statement of implication. If I have an a and an f, the most I can have is a function which takes arguments of type B, C, and D, and so forth.
contains :: (NameClass, QName) -> Bool
or contains :: NameClass -> (QName -> Bool)
In other words, you can treat it as a function taking two arguments, or one function taking one argument and returning another function.In it kinda the case in C++ too. C++ template system is a turing-complete machine at compiling time.
TemplateHaskell --DSLs that are transformed to (mostly rather repetitive) Haskell at compile time-- are MP in my idea, also: macros in LISP and open classes modified my the program at runtime in Ruby.
Non the less a very interesting article! Compared to C++ Haskell's syntax is soo clean!