15 ms·
I for one can't wait for Typed FP to become mainstream as soon as possible. I think the prevalence of scripting languages in large systems today is a quirk of h
by jasim 8y ago
I for one can't wait for Typed FP to become mainstream as soon as possible. I think the prevalence of scripting languages in large systems today is a quirk of history.
In early 2000s, as the web was growing to be an application delivery platform, the only practical statically typed language was Java. It didn't have generics or lambdas at the time, and was infested with the sprawl of J2EE. Choosing Ruby/Python over Java was at the time an act of rebellion and a show of technical superiority. To quote pg: "if they wanted Perl or Python programmers, that would be a bit frightening-- that's starting to sound like a company where the technical side, at least, is run by real hackers."
The static type system in Java is object-oriented: the only way to create a type is to create a class. I believe it was limited in abstraction power and everyone attributed it to the rigidity of static types. Java has come a long way since, but the sense that dynamic typing is superior to static types lingers.
But OCaml's static types are a completely different kind of type. There is a kind of "procedural" static typing in Go, C, and to some extent C++ where primitives are typed and you can construct structs and unions without much ceremony. Then there is object-oriented static typing in Java and C#, which traces its origin back to Simula through C++ where types and classes are the same. Then you have functional static types where types are just and only about data. Almost all Typed FP languages use a form of Hindley-Milner inference, support algebraic data types and pattern matching, have generics (they were invented by Milner for ML in 1973), and allows for code organization and encapsulation through modules and opaque types.
Algebraic data types alone is a tool for thought like no other. You'll start reifying concepts that would've otherwise gone implicit in your codebase thanks to ADT. The languages are solid, ecosystems are vibrant but small and that can only be fixed with more people. Come on in, the water is fine!
- MaxBarraclough 8y ago> I think the prevalence of scripting languages in large systems today is a quirk of history. Disagree. This is happening because software development has become an enormous industry, and is now subject to Sturgeon's Law. If the bulk of software development really was about correctness and quality rather than rapid development and low skill barriers, we'd be seeing a lot more Ada and OCaml, and a lot less JavaScript. But here we are, and it's not going to change just because someone makes a technical breakthrough in the design of functional programming languages.
- deleted 8y ago[deleted]
- weberc2 8y agoJS's popularity is the canonical example of "a quirk of history". It is popular solely because until roughly now, it has always been the _sole_ language for the enormously popular web platform. Better proxies would be Go and Ruby since both occupy the same niches; however, this doesn't support your point as Go has grown much, much faster than Ruby.
- kqr 8y agoNot contradicting your other excellent points in any way, but I'd argue the Java type system is better described as "class oriented" rather than object oriented. OOP is a rather wide umbrella of techniques, involving inheritance, abstraction, encapsulation, etc, all of which can be supported in ways very different from the "let's build everything on the concept of classes" approach taken by Java.
- ofrzeta 8y agoNice. Now the big question is what language to pick, because if there are many small communities around each language it won't help the cause. I see Elixir (also mentioned in this thread) getting some traction. Like most of the time its success is mainly due to a singular project with a specific application, namely web programming in Phoenix. Just as back then with Ruby and Rails. Probably F# would be a better candidate for mainstream adoption with a vast .NET ecosystem and the open source release of .NET Core.
- proaralyst 8y agoElixir is not statically typed. It's definitely interesting but you don't get a lot of the same safety as you do with ML.
- zinclozenge 8y agoIn fairness, a lot of the 'safety' in BEAM languages is delegated to processes. It's ok for a process to crash.
- jasim 8y agoFrom my biased perspective, it could be OCaml thru Reason. The .NET/Microsoft ecosystem is a no-go for a lot of people, and F# doesn't have functors. Being a statically typed language, you don't have something like Ruby's mixins to share code, nor do you have OO's interface inheritance. Functors fill this gap by allowing you to mint new modules out of existing modules, and is a powerful way of achieving modularity. Simon Peyton Jones critiques that while OCaml's modules are very powerful, the power/cost ratio is not very favourable. And it is true - there is a bit of learning curve, but I think it can be eased as the community grows. For good or for bad, Javascript is the lingua-franca of computing today if adoption is any measure, and anything that goes against its norms face strong downdraft (try getting Ruby+Opal mainstream adoption). But the updraft can be useful (I'm probably the only person on the internet who don't understand React Hooks yet which was announced just a few weeks ago). Reason is Javascript++: the syntax is very close, and it compiles to vanilla JS with great interop with npm. The promise of gradual adoption I think is a good marketing lever. We'll see in a few years. There is also Elm, which is just so good for building rich web applications on the browser. It is a language with wonderful aesthetics, clear long-term vision, and avoids importing the complexity of academic research, which is often the case in other typed functional languages. But you don't really need to pick a language more than you pick Typed FP. F#, Haskell, and PureScript are great as well - each has different tradeoffs. But once you understand the set of features underpinning Typed FP you can move around languages with relative ease, and that's what I think matters most.
- zengid 8y agoNot trying to contradict you, but I think C# is special in than it has absorbed a lot of things from the academic functional programming world and presented them in a nice 'friendly' form for the masses; IE, LINQ; first class functions like delegates and Func<> and Action<>; and now tuples and pattern matching in C# 7 (among many other things). I know having mutability the default still lets one shoot themselves in the foot (and nullable reference types), but I'm always impressed when I find more of the nice FP ideas baked into the language. It's a pretty good compromise for me.
- jasim 8y agoMy cursory experience with C# was very pleasant too, and Erik Meijer managed to put in some monads into the language thru LINQ when no one was looking (https://queue.acm.org/detail.cfm?id=2024658 https://queue.acm.org/detail.cfm?id=2024658) Java 8 was a joy to work with as well - FP is filtering down through lambdas and map, filter, fold et al.
- markdoubleyou 8y agoGreat article, thank you for sharing!
- bad_user 8y agoFunctions in C# aren't really first class. A static method for example isn't a Func< > or an Action< > and neither are normal methods, both of which are prevalent. To say that C# has first class functions is a misnomer. And on anonymous methods (delegates), Func< > and Action< >, that there's even a difference between the 3 shows C#'s age and some of its quirks. > now tuples and pattern matching in C# 7 Note the pattern matching in C# is a far cry from what you get normally in FP languages. First of all C# does not have ADTs, which means it cannot do exhaustiveness checking, making pattern matching only a superficial syntactic sugar. Tuples are nice though. > academic functional programming world and presented them in a nice 'friendly' form This is sort of a marketing myth. C# is not an FP language and I rarely see actual FP built in C# (same goes for Java). In my opinion you should try out the languages in the "academic functional programming world". Because you'll then notice that C#'s way of doing things is not "friendly", unless by that you mean half baked and annoying ;-)
- plinkplonk 8y ago"I for one can't wait for Typed FP to become mainstream as soon as possible." This will never happen till there is a typed FP language that has solid tooling, documentation, solid libraries for most common programmer tasks, a welcoming and active community and at least one of a killer app, or framework (Rails for ruby), killer platform (objective c/swift for AppStore dev) or targets an underserved domain (Julia for Scientific Computing). The existing typed FP language implementations (OCaml, Haskell, SML, not sure of F#) are full of cruft and/or are just lacking with respect to one or more of the above. Haskell comes the closest I think, but that maybe because I've been using Haskell for decades, and so I am biased in its favor (and I'd still hesitate before using it on a large team + long timescale project). Try writing a 'mainstream' application in any of the above, and you'll see what I mean. Yes you can write a typical web app /CRUD app/mobile app in (say) Haskell, but to be honest, Yesod (say) is no Rails. Reason might be 'the one' I guess, at least in bringing TypedFP to the javascript ecosystem, especially with FB's corporate backing. Rust gets/is getting most of the above right, but it isn't really an FP language. OCaml or Haskell being the mainstream will never happen imho. If there is a TypedFP mainstream language in the future, it is yet to be invented (or is being invented right now! touch wood). What is more likely to happen is some FP features moving into mainstream languages. Not sure if that counts as "typed FP becoming mainstream", but it likely to be a long wait ;-) I honestly don't see any typed FP language ever having the success of say, Python, for at least a few decades yet. (all imho, ymmv, as it should)
- jasim 8y agoThe killer app for OCaml is front-end webdev with Reason. Most new large-scale Javascript projects are using gradual typing with TypeScript, and the experience is not the same as having types natively. It gives you the safety and rigidity of types, but not as much the ability to think with types. These projects also toy around with immutability - using a library like Immutable.js which is a boxed data structure that needs explicit handling and conversion to and from native types, need to pick a state management library like Redux which implements a version of variants through constants and manual dispatch, and all these projects need large test suites to check for things that types would've caught and so on. A typed functional language eliminates almost all of these issues and grants more powers of abstraction. If not Haskell or OCaml, I suspect Elm has a good shot at it. I'm all for new languages! If I remember correctly, the ideal one is Lispy with Hygienic macros, ML-like type system baked in, multi-core, good stdlib, and tools that don't stand in your way.
- japanuspus 8y agoRust is actually a contender in this space as well [0]. It is not something that is widely touted, maybe because of a fear that an FP-label would give rust an academic tinge? This is one of the reasons I will dedicate this year's advent of code [1] to learning rust. [0]: https://science.raphael.poss.name/rust-for-functional-programmers.html https://science.raphael.poss.name/rust-for-functional-progra... [1]: https://adventofcode.com/ https://adventofcode.com/
- christophilus 8y agoMy vote is still for OCaml, if for no other reason than the compiler speed.
- pjmlp 8y agoAnd memory management productivity. I agree GC free management is necessary, but it should be constrained to certain high performance niches, which cannot cope with GC + value types.
- pjmlp 8y ago> In early 2000s, as the web was growing to be an application delivery platform, the only practical statically typed language was Java. We also had Eiffel, Delphi, VB, Component Pascal, Oberon back then. But Sun was pumping money and offering the JDK as free beer.
- whyever 8y agoThere was also SML, which is not so different from OCaml.
- qwerty456127 8y agoI've been mesmerized with FP and algebraic typing as soon as I've tried Scala. But now I end up wondering why would anybody choose something other than Clojure or Scheme. Nevertheless I currently use Python because 1. really great and alive library ecosystem (Pandas, Numpy, Keras and PyQt especially) 2. everybody codes at least some Python, this way whatever I write it is actually going to be hackable by everybody. I just hope Reason is going to be more successful that F# in going mainstream an will actually replace JavaScript for React developers at least. I also hope an option to force "type hints" (I put them all over the code) is going to be introduced in future versions of Python and Hy language support (Hy is a Lisp over Python, like what Clojure is for Java) is going to be introduced in future versions of PyCharm.
- icebraining 8y ago>I also hope an option to force "type hints" is going to be introduced in future versions of Python Have you checked https://mypy.readthedocs.io/en/latest/command_line.html#untyped-definitions-and-calls https://mypy.readthedocs.io/en/latest/command_line.html#unty... ?
- qwerty456127 8y agoLooks curious, thanks. Nevertheless it (or a part of it) has to become a part of the CPython standard and get switched on by default at some point for the quality of the ecosystem code to start increasing by means of more Python coders being gently pushed to type-mindfulness. I also couldn't find a flag that would rise warnings when a value of a non-matching type gets assigned to a variable with a defined type hint yet allow everything else - IMHO such one would be the most useful.
- craigsmansion 8y agoI hope it never happens. Ocaml is now in that sweet spot where it's big enough for real work, but can ignore mainstream fashions and keep out the inevitable accompanying "how to program when you cannot" crowd. The last thing Ocaml needs is mainstream attention. FB's "Reason" being a point in case: "Since I don't understand what I'm doing, can you at least make the syntax look familiar?" Let the masses stick to writing UX-driven apps in Javascript. It's where the money is anyway, which seems to be the primary motivation for "software engineers" these days.
- oblio 8y agoI absolutely abhor this elitism. If something is truly worth it, it should be accessible to the "masses". The polish and QA investment mass adoption provide make for much more solid products. It's not like Ocaml would be sold in stores, next to Coke Light.
- craigsmansion 8y ago"The polish and QA investment mass adoption provide make for much more solid products." That's pretty much untrue unless by polish you mean "pretty but pointless IDEs and buzzword/checkbox compliance." Ocaml is already very accessible, just on its own terms.
- oblio 8y agoI guess this is a sort of: > Unix is user-friendly — it's just choosy about who its friends are. > Anonymous, in The Art of UNIX Programming (2003) by Eric S. Raymond At the end of the day, each community chooses its path. If Ocaml makes you happy how it is now, more power to you :)
- weberc2 8y ago> Ocaml is already very accessible, just on its own terms. i.e., "ocaml is already very accessible to people who know ocaml"
- progman 8y ago
- weberc2 8y agoI agree with the points in your post and I also want a mainstream typed FP (something with a clear happy path so I don’t need to guess about what prelude or string types or standard library or etc to use). The biggest impediment I see is that these language communities are more concerned about the abstract mathematical properties of the language and things like tooling get neglected. I would love to see a typed FP equivalent to Go—everything is super simple/small learning curve (I should be able to meaningfully contribute to a project after a day or so), the standard library is decent, package management just works, no guessing about what test lib to use, everything compiles to a single static binary by default (dead simple deployments), no-fuss documentation generation, great concurrency/parallelism story, straightforward profiling and optimizations (e.g., if my program is slow because I’m allocating too much in the hot path I can trivially preallocate), etc. These are the things that matter for real world projects—mathematically elegant type systems really are just gravy, which is why Go has been able to be so successful in spite of its flat-footed type system.^1 ^1: if you go over to r/programming, no one can figure this out because everyone believes you can’t ship Software in a language without monads or generics, so Go’s popularity must be due to Google marketing.
- akavel 8y agoPersonally, I see Elm as an interesting development in such a direction, i.e. humane FP language, with the author relentlessly striving for simplicity and ease of use kin my opinion, successfully). That said, it's currently limited to a web dev./"frontend" domain (JS replacement).
- vram22 8y ago>Personally, I see Elm as an interesting development in such a direction, i.e. humane FP language, with the author relentlessly striving for simplicity Red is another language that is or was striving for simplicity (or resisting the complexity that seems to be the norm in tech nowadays). In fact that was supposed to be one of its main goals. I felt sad when they went down the ICO route for funding, though. Not sure how FP-ish Red is, though. Rebol, which Red is based on, is supposed to be homoiconic. I like Rebol and Red. The size of the Rebol and Red interpeters (and Red is a compiler too) and the size of the Red EXEs are quite small, which is another plus. Much smaller than some other languages.
- paganel 8y ago> Choosing Ruby/Python over Java was at the time an act of rebellion and a show of technical superiority. Not much of a rebellion, it was just that back then you had instant access to Python's REPL by just typing "python" in any Linux distro terminal. A Python "program" could have been just a simple script_that_does_stuff.py file run from the same terminal with: > python script_that_does_stuff.py On the other hand Java was a total mess. Source: me, a Python programmer for 13+ years who directly referenced this (famous at the time) "Python is not Java" blog post [1] during my first interview for a programmer job [1] https://dirtsimple.org/2004/12/python-is-not-java.html https://dirtsimple.org/2004/12/python-is-not-java.html
- amelius 8y agoI can't wait until code augmented with general formal proofs (not just types) becomes mainstream in e.g. kernel modules.
- arwhatever 8y agoGive me Algebraic Data Types or give me death.