jakt
jakt copied to clipboard
Support Uniform Function Call Syntax
It would be awesome if jakt supports UFCS
Is this also a call for currying and/or partial application? (Would also be nice if possible).
No, this actually doesn't have much to do with functional programming but it definitely helps to use the functions in a way that is more apropriate for the task. It's also great for extending the class/struct behavior outside of the class/struct definition...
If traits (parametric type system) are landed, the unified function call is for free because you can determine the set of names to look up even in a generic function. ~~That's how Rust does it as well.~~
@zhihaoy How exactly do you do it in Rust? I'm not aware that Rust can use free functions as methods...
I was mistaken by how Rust uses this term, it's something different... Anyway, let me explain the idea of how traits/protocol can help. With trait,
trait Reader {
fn Next(&self) -> String;
}
Right now you read self
as something special. It doesn't have to be, not in Haskell's typeclass, for example. You can understand a trait as a concept that the type that implements it must satisfy, while each function is just a free function that lets you do
let tok = Next(reader);
And because a type implements Reader
, you can now call reader.Next()
as if impl
works as adding an extension method - only in the context of generic function like this
fn foo<T: Reader>(reader: &mut T) -> ()
{
let tok = reader.Next();
It looks like golang interfaces a little…? 🤔
(Those are pretty neat in my opinion; itʼs even a little bit more: the compiler finds whether trait/protocol is met and takes care of resolving the type of a value)