3 ms·
I gave quick look at the example. First reactions coming from OO languages and Elixir: I can imagine that this def addCandidate(A ~Int, B ~Int) do means
by pmontra 11y ago
I gave quick look at the example. First reactions coming from OO languages and Elixir:
I can imagine that this
def addCandidate(A ~Int, B ~Int) do
means that addCandidate has two arguments of type Int, but what does the ~ mean? I'll have to read the docs.
However I have really no idea of the meaning of
def bar(arithFn ~Function(Int -> Int -> Int)) do
It's a function bar taking arithFn as argument, which is a function with... what arguments?
From the demo program it looks like a function with two int arguments returning an int, but why the -> signs and why isn't addCandidate defined as (Int -> Int -> Int) too? Where is it's return type. Maybe inferred?
It's quite puzzling and there are no explanations about that in the README.
Is the ~ necessary? Could it be removed and save one character that's not even on some keyboards around the world?
Apart from that lack of explanations, it could a perfectly nice language and it's a great project for sure.
- auxym 11y agoFunction signatures like (Int -> Int -> Int) should be familiar to anyone familiar with functional languages (f#, ocaml and haskell come to mind as having similar notation). I would also assume the return type of addCandidate to indeed be inferred. That said, maybe the README does lack a bit of introductory text, especially if their targeted audience is programmers in general.
- naasking 11y ago> From the demo program it looks like a function with two int arguments returning an int, but why the -> signs? This is standard syntax in functional languages. A->B is a function from A to B. A->B->C is a function from A that returns a function B->C. This is the standard curried function application, like used in OCaml, and it enables you to easily partially apply and compose functions. addCandidate's type is indeed Int->Int->Int, it's simply not declared that way. In OCaml, the following two syntaxes are equivalent: let addCandidate = fun A:Int B:Int -> ...body... let addCandidate A:Int B:Int = ...body... I imagine this language is similar.
- artagnon 11y agoYes, I'd implemented the syntax with the intention of doing currying, but haven't gotten around to doing that yet. If you want to do any "partial application", you need to write a lambda, and explicitly pass its function pointer now. The next step is to automatically generate the lambda.
- artagnon 11y agoThanks for the feedback. The ~ is a substitute for :, which is used in other languages for optional type annotations. You're right about removing ~ altogether, Go style. ~Function(Int -> Int -> Int) is a function which takes two integers, and returns one. I've mixed in some Haskell syntax there. And yes, return type is inferred. There are two reasons for there not being explanations in the README: 1. I foolishly thought it would be obvious. 2. I wanted to focus on the implementation, not the language itself. In any case, I've added them now, thanks.
- phamilton 11y agoI think the bigger point of feedback is that anonymous function signatures are drastically different from defined function signatures.
- pmontra 11y agoThanks to everybody for all these explanations! I understand the logic of the syntax now. A nice thing with Elixir is that it lures OO developers like me into the realm of functional languages with a familiar syntax. Int -> Int is not familiar to me. I could guess what it is but then I also see an Int, Int and feel a little puzzled. If one of the goals of this language is to "convert" OO developers maybe you should consider a syntax they are fully familiar with. You could make long time functional developers feel not at home though. Maybe it's a trade-off that's impossible to avoid. It's your call.
- Kabie 11y agoWhy `~Function(Int -> Int -> Int)` instead of `~Int -> Int -> Int`?