5 ms·
> As a matter of fact, it's what the compiler devs keep recomending. I definitely agree with them in this matter. Macros might have a role in language developm
by abstractcontrol 8y ago
> As a matter of fact, it's what the compiler devs keep recomending.
I definitely agree with them in this matter. Macros might have a role in language development, but they should not be a stand in for compiler optimizations. For safety and speed, the type system should be there.
https://github.com/mrakgr/The-Spiral-Language/blob/0741959acdb9c97ad8c0da2e9712e44b8a26c34b/Testing/run.fs#L17 https://github.com/mrakgr/The-Spiral-Language/blob/0741959ac...
Here is how the example you've shown could be done in Spiral. Maybe I should add express support for literal testing in pattern matching, but it is not a pattern that comes up too often by itself.
> I feel like what Julia does is just more low level right now - And you get pretty far with just multiple dispatch!
What you say is exactly right as pattern matching compiles down to those low level operations, so there no reason at all why those low level operations should be done by hand. Pattern matching does not depend on a particular type system or whether the language is dynamic or static. There are only so many good ideas in programming languages and this is one of them.
Though there is some overlap between pattern matching and multiple dispatch, the roles are different. The purpose of multiple dispatch is extensibility, but the purpose of pattern matching is destructuring.
https://stackoverflow.com/questions/2502354/what-is-pattern-matching-in-functional-languages https://stackoverflow.com/questions/2502354/what-is-pattern-...
Note the great disparity in the F# examples that do pattern matching and the C# examples that do manual reflection.
https://github.com/mrakgr/The-Spiral-Language/blob/0741959acdb9c97ad8c0da2e9712e44b8a26c34b/The%20Spiral%20Language/SpiralTests.fs#L542 https://github.com/mrakgr/The-Spiral-Language/blob/0741959ac...
Here are a few very simple examples of it in action in Spiral. I use them as compiler tests.
https://github.com/mrakgr/The-Spiral-Language/blob/0741959acdb9c97ad8c0da2e9712e44b8a26c34b/Learning/CudaModule.fs#L1754 https://github.com/mrakgr/The-Spiral-Language/blob/0741959ac...
Here is quite a complex example of how it is used in action. I won't go into detail of this here, but you can see how I repeatedly match on the contents of a module at different times in order to get more generic functionality for the kernel.
The particular kernel shown here is the most complex one that exists in the library right now - I am yet to get to things like generic matrix multiplication and convolution, but I'll get there eventually.
> I see how it sounds nice, but I can't really imagine right now how it would improve my life.
Let me just say that it is really difficult to know ahead of time how a particular language feature would affect your programming life. I could have said the same thing about first class functions back in 2015. I am sure in the future there will be such features I can't even imagine right now.
> And if we don't get it as part of the compiler, we can definitely do things like that with https://github.com/jrevels/Cassette.jl/ https://github.com/jrevels/Cassette.jl/
I'll have to watch the talk on this. Thanks for the link.
- simondanisch 8y ago>The purpose of multiple dispatch is extensibility, but the purpose of pattern matching is destructuring. Agreed! ;) Just wanted to point out, that I was able to use multiple dispatch elegantly in the unroll example, where you are using pattern matching. >pattern matching compiles down to those low level operations So I guess that means Julia could indeed satisfy you, if we gave those low level operations some more syntactic sugar? Have you seen: http://kmsquire.github.io/Match.jl/latest/ http://kmsquire.github.io/Match.jl/latest/ ? >Let me just say that it is really difficult to know ahead of time how a particular language feature would affect your programming life True story. I'll try to be more observant when writing code and see, if I could actually solve things more elegantly with better pattern matching. Btw, I'm writing on an article about GPU programming in Julia - do you have feature you'd like to have explained, or a killer feature you believe we can't do and that would impress you if we did?