Tag Info

Hot answers tagged

13

It's called arrow token Here on wiki, this article and that article or even on java website Many years ago, before there were any computers, the logician Alonzo Church wanted to formalize what it means for a mathematical function to be effectively computable. (Curiously, there are functions that are known to exist, but nobody knows how to compute ...


9

The basic unit of an imperative program is the statement. Statements are executed for their side effects. They modify the state they receive. A sequence of statements is a sequence of commands, denoting do this then do that. The programmer specifies the exact order to perform the computation. This is what people mean by telling the computer how to do ...


9

You seem to be drawing a line between declaring things and instructing a machine. There is no such hard-and-fast separation. Because the machine that's being instructed in imperative programming need not be physical hardware, there is much freedom for interpretation. Almost everything can be seen as an explicit program for the right abstract machine. For ...


6

However, I lose the benefits of functional style. If you always lose the benefits of functional style code when converting bundles of functions to objects, you're doing it wrong (or have an usual idea of what the benefits of functional style are). After all, instance functions are the same thing as static functions but simply have an additional ...


5

The real defining characteristic that separates declarative from imperative programming is in declarative style you are not giving sequenced instructions; at the lower level yes the CPU operates this way, but that's a concern of the compiler. You suggest CSS is a "declarative language", I wouldn't call it a language at all. It's a data structure format, ...


5

Even though you said algebraic data types, you seem to mostly be asking about sum types, so I will focus on those. Product types are more common and more easily understood. Sum types are most easily understood not by thinking about what you're modeling, but by thinking about the code that uses it. People tend to think of sum types as representing states ...


5

What is it about Haskell that has led to it's rise in popularity among experts in the FP world? There's a few of different things I've seen: It's novel. As much as FP enthusiasts poo-poo all of the fads in imperative and OO programming, they're still human. Lisp has been around since the 60's. ML since the 70's. A lot of people have spent a lot of ...


4

Hm, well for the first one this is because let's say f f was well typed. We're applying f so it has to be a function. Functions have the type f : A -> B for some A and B. Since f is also the argument, it must also be the case that f : A. This means that A = A -> B. Moreover since f = f f, the the type of f f is also the type of f. Since f f : B this ...


4

Encapsulation is not a feature that came with OOP. Any language that supports proper modularization has it. Here's roughly how you do it in Haskell: -- Rational.hs module Rational ( -- This is the export list. Functions not in this list aren't visible to importers. Rational, -- Exports the data type, but not its constructor. ratio, ...


3

Do you know of guidelines and best practices that guide through modelling logic in types properly? Sure, at least in theory. Algebraic Data Types are made of two parts, sum types (or variants, or discriminated unions, or...) and product types (or tuples; conceptually records and classes fall here, but some disagree). Product Types are used when you ...


3

To reflect the changed state of an object (I will call this object now and reference with this to the OOP paradigm) you can return this object again which in itself is immutable again, e.g. playerOne = doSomeMove(playerOne) Basically this is the idea behind the state pattern. With this the single object is immutable but your changes are reflected by ...


2

I don't think that simply using static methods makes it Functional I don't think simply moving your previously static methods to a class makes it OO If you are doing OO, then your classes should have properties and the methods should change those properties. This makes the 'data object' mutable and functional programming goes out the window While Static ...


2

I'd go with the second approach, with a change which releases the handle when done. If each method takes care of getting, operating and releasing its own handle, then your application should be better suited to scale up (assuming you have some sort of pooling underneath). With the first approach, it is hard to say what will happen should two different ...


2

Some functional languages such as OCaml have built-in mechanisms to implement abstract data types therefore enforcing some invariants. Languages which do not have such mechanisms rely on the user “not looking under the carpet” to enforce the invariants. Abstract data types in OCaml In OCaml, modules are used to structure a program. A module has an ...


2

You do it the same way: make a constructor that enforces the constraint, and agree to use that constructor whenever you create a new value. multiply lhs rhs = ReducedFraction (lhs.num * rhs.num) (lhs.denom * rhs.denom) But Karl, in OOP you don't have to agree to use the constructor. Oh really? class Fraction: ... Fraction multiply(Fraction lhs, ...


1

You can write functions even when using classes. You said you created static functions, so there is no "state". When you move those methods to their respective classes, of course they can't continue to be static, they need to be regular instance methods. But if you don't modify any of the parameters, even the receiver of the message (which is the same as ...


1

At the topmost level, you can use a fold to feed the output of the last step into the input of the next step without having to give it an intermediate name that gets reassigned. Basically, at each step you create a whole new scope. This part is a lot easier with functional reactive programming or actors. Below that level, the key insight is because of ...



Only top voted, non community-wiki answers of a minimum length are eligible