Re:Translating Haskell to C++ metaprogramming
by igravious on Sunday July 12, 2015 @09:56PM
(#9875948)
What? Are you saying that I can legitimately read
two ways? Like,
And
? What about four types?
[ Parent
| on HN ]
No, a -> b -> c always means a -> (b -> c).
a -> b -> c -> d always means a -> (b -> (c -> d)).
"->" is right-associative.
You should first understand currying. If I have a function f :: A -> B -> C -> D, every time I apply an argument, as in f a where a is of type A (b :: B, c :: C, ...), you get a new function back of type B -> C -> D. Read :: as "has type." Therefore
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.
Re:Translating Haskell to C++ metaprogramming
by Nullabillity on Sunday July 12, 2015 @10:03PM
(#9875967)
Not quite. It's equivalent to either
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.
Re:Translating Haskell to C++ metaprogramming
by theseoafs on Sunday July 12, 2015 @10:29PM
(#9876041)
It is equivalent to the second, not the first. The first is a completely distinct type -- though you can certainly write a function with that type, given the original function, by uncurrying it.
FWIW, I think the person you are responding to is using the non-Haskell requested mental syntax used by the person who asked the original question, in order so they better understand the semantics (even if at a cost of confusing them for later development in Haskell).
Re:Translating Haskell to C++ metaprogramming
by Nullabillity on Monday July 13, 2015 @06:11AM
(#9877207)
Yup. They're distinct types, but mentally they are the same (and the standard library has functions to convert between the two forms).