5 ms·
On a serious note, I've long wondered what python would feel like with haskell-style "whitespace" to call/partially call functions. It feels like it wouldn't be
by misnome 7y ago
On a serious note, I've long wondered what python would feel like with haskell-style "whitespace" to call/partially call functions. It feels like it wouldn't be super difficult to get working; as far as I can think of "identifier ws identifier" is always currently a syntax error? Maybe a toy python project someday...
- TylerE 7y agoImplicit string concatenations are an edge case.
- eru 7y agoFun fact: you can make Haskell support implicit string concatenation, but it's a bit ugly and not advised. The route is via the OverloadedStrings extension, and then implementing an instance for IsString (String -> String) and IsString (String -> String -> String) etc.
- nestorD 7y ago> haskell-style "whitespace" to call/partially call functions That's called curryfication (named after the logician Haskell Curry) in case you don't already know :)
- DonaldPShimoda 7y ago> That's called curryfication I believe this is how it's called in non-English languages, but all my instructors and PL/semantics textbooks referred to this process as "currying" [0]. Which, if that's what you meant, is not what your parent comment was talking about. I believe they were talking just about syntax, not semantics, i.e., they wish in Python you could do `foo x y` instead of `foo(x, y)`. [0] https://en.wikipedia.org/wiki/Currying https://en.wikipedia.org/wiki/Currying
- gmfawcett 7y agoActually, that's a common misconception. If you're calling a function with a partial argument, it's called "partial application." If you're turning a multi-arg function into a single-arg function that returns another single-arg function, it's currying. Currying doesn't apply a function, it just transforms it. https://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application https://en.wikipedia.org/wiki/Currying#Contrast_with_partial...
- koenigdavidmj 7y agoPython has enough vararg functions to make this not doable without coming up with some special-case syntax. There's a reason you don't have varargs in the Haskell world--currying isn't a special case, but rather happens any time you have multiple arguments. A three-argument function with type (A -> B -> C -> D) is actually syntactic sugar for a function that takes an A and returns... a function that takes a B and returns... a function that takes a C and returns... a value of type D. This is determinable by just looking at the number of arguments provided. But a variadic function, in a world with currying, would be a function that takes an argument, and returns...well, it might be a function to take another argument, and it might be the actual computation. Even if we didn't have currying, we can't just use whitespace in a Python-like language. We don't know if (print) is actually a function call, or just referencing the function object (perhaps to pass it to 'map' or something). Your syntax needs to distinguish between those two cases.
- ferzul 7y agoi thought i disagreed with you, but then i realised you're referring to the possibility of a unary procedure call in python. but there are strict impure languages with white space function application. i suppose they handle the issue by using an object of a type with only one value. in principle, you could handle the issue by contrasting (print) with (print ()), with () a pseudo value only existing at syntax level. i'm not sure if white space function application carries it's own weight once we abandon partial application, so this feels like a contrivance to save a bursted balloon.
- eru 7y agoThere are varargs in Haskell, but they aren't as natural as in Python; and usually rely on various amounts of type level trickery. Implementing a vararg printf in Haskell is a popular enough exercise. A relatively common examples in practice is the testing library QuickCheck: your properties (ie tests) can take any number of arguments that the library fills with samples inputs.