4 ms·
You can like lambdas without wanting to go fully functional... just like you can like objects without wanting to go fully object-oriented.
by bruceboughton 16y ago
You can like lambdas without wanting to go fully functional... just like you can like objects without wanting to go fully object-oriented.
- gaius 16y agoThose are called structs ;-)
- bruceboughton 16y agoNot everyone accepts that the object systems in Java and .NET are fully object-oriented.
- loup-vaillant 16y agoConsidering that no definition of "object-oriented" is accepted by everyone, I'm not sure your criticism is valid. My suggestion: drop the term "object-oriented" altogether, and refer to more specific features.
- bruceboughton 16y agoWhich brings me back round to my initial assertion: >> You can like lambdas without wanting to go fully functional
- loup-vaillant 16y agoWell, F# and Ocaml aren't purely functional… so you're right.
- loup-vaillant 16y agoWell, I'm not sure. First, assignments are evil[1], which means you should avoid setters. Second, inheritance is evil, for similar reasons (thick interface). Third, every time I saw mixins or class polymorphism, lambdas or sum types, would have been simpler, respectively. Once you like lambdas, functional programming becomes more attractive than a black hole. [1]: http://www.loup-vaillant.fr/articles/assignment http://www.loup-vaillant.fr/articles/assignment
- barrkel 16y agoSum types are not as dynamically extensible at runtime, or by third party libraries, as class polymorphism.
- loup-vaillant 16y agoFor the particular cases I saw, runtime extensibility never mattered. (Do you have one where it does?) And extending a third party sum type is not very hard: data LibType = Zero | One Int | Two Int Int data MyType = ZeroOneTwo LibType | Three Int Int Int (It of course implies that you use MyType instead of LibType in your code.) Finally, if you really want to extend a sum type, no work around allowed, you might want to look at Ocaml's variant types.
- vetinari 16y agoThe keywords were "extensible dynamically at runtime", not just "extensible, period". Runtime extensibility matters at systems that you cannot shut down, where have to upgrade live systems, for example. If you are doing just "run it once again, no big deal" application, then it does not matter, you are right.
- barrkel 16y agoThe code using LibType is code you don't control; you can't change it to use MyType instead. Indeed, you don't even have the source code to it. That's also why the extensibility happens at runtime.
- loup-vaillant 16y agoSo What? Just do what you would have done in Java without inheritance: aggregate. For each function that matters, you can write a new one that handle the extra case: new_function ZeroOneTwo x = old_function x new_function Three a b c = -- handling new case
- 16y ago
- jamii 16y agoNote that both F# and Ocaml have object systems and have excellent support for imperative style programming. http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html#advanced http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-objects.html#ad...
- jules 16y agoNote that OO programming in F# requires a lot of type annotations (even more than in C#, you need to explicitly upcast).