4 ms·
I think Julia has a neat answer to the Expression Problem: - To add a case to a type, the type needs to be abstract, which allows you to declare concrete subty
by fanf2 6y ago
I think Julia has a neat answer to the Expression Problem:
- To add a case to a type, the type needs to be abstract, which allows you to declare concrete subtypes. (Julia's subtyping is not OOPy, and it doesn't have FP-style algebraic types.) Then you can add methods to generic functions that are called when passed an argument of your new concrete type, when they need special cases.
- To add operations to an existing type, define a new generic function. You can often do so using just abstract supertypes, and let the compiler optimize to concrete types, but you can also define special-case methods for specific concrete types if you need to.
- Xcelerate 6y agoClicked on the article to post the same thing. I haven’t really had this issue any more since using Julia.
- Mathnerd314 6y agoYes, Julia has multimethods. This is called out in the article: > Open functions (functions that can be extended with new pattern-matches), open data-types (data types that can be extended with new patterns), and MultiMethods ('open' specialized polymorphic functions with 'open' set of classes), and PredicateDispatching, are all viable approaches.
- Jtsummers 6y agoThat same multiple dispatch approach is in Common Lisp, though not used to as great an extent as in Julia (that is, things like + aren't open to extension without shadowing the main definition and creating your own).
- choeger 6y agoI might be wrong, as my contact with Julia has been a while ago. But IIRC, Julia, having no type checker [1], cannot check whether every function is complete regarding the type in question. This is somewhat comparable to OCaml's polymorphic variants, which only solve the expression problem if you give up the completeness check of pattern matching. [1] yes, I know it does a lot of run-time stuff with things called types, but that's something fundamentally different. Really.
- eigenspace 6y agoMy eyes just rolled so hard they might be stuck in the back of my head.
- choeger 6y agoBecause you think that calling Julia a typed language is good for marketing?
- neolog 6y agoIt sucks when moving from Python that I lose Mypy. Very helpful to have a production-quality type checker, even an imperfect one.
- dang 6y agoPlease don't sneer. That's in the site guidelines: https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html. If you know more than another commenter, that's great, but in that case share some of what you know so the rest of us can learn. Responding to bad information with good information improves this place; just putting others down makes it worse.