Tag Info

Hot answers tagged

44

which seems to be the more mathematical way functional languages are inspired by lambda calculus. In this field, parentheses are not used for function application. I also think that the latter style is much more clear and readable than without the parens. Readability is in the eye of the beholder. You are not used to reading it. It is a bit like ...


27

Functional programming is all about gluing smaller functions together to achieve your results. A decent mental model (for me, at least) is an assembly line. Each function that gets composed is one more step in the assembly process. Consider this function here: smallest = head . sort In Haskell, this function will return the smallest element in a list. ...


16

The basic idea is to make the most important operation (function application) easiest to read and easiest to write. A space is very unintrusive to read and very easy to type. Note that this is not specific to functional languages, e.g. in Smalltalk, one of the first OO languages and languages inspired by it (Self, Newspeak, Objective-C), but also in Io and ...


14

There is no such thing as an "interpreted language". A language is a set of abstract mathematical rules. A language isn't interpreted or compiled, it just is. Interpretation and compilation are traits of, well, the interpreter or compiler (duh!), not the language. A language is an abstract entity, an interpreter or compiler is a concrete implementation of ...


13

Parenthesis for function application is just one of the many saddles Euler left us with. Like anything else mathematics needs conventions when there are several ways to do something. If your mathematical education only extends as far as a non-maths subject at university then you probably aren't too familiar with the many fields where function application ...


12

Does anyone have a good mental model for functional programming? Mathematics. Functional programming is inspired by and modeled on mathematics. Mathematical functions don't have state, don't have side effects, etc., and so it is with FP. If you think about FP in terms of mathematical functions rather than using an OO-style "how do I do this to that" ...


10

Mutable state is easily avoidable using immutable objects. In the same way, global variables are usually the choice of the developer (or a poorly implemented framework). This being said, you may also want to use additional functional paradigms in non-functional languages. It's all about the expressiveness of your code. If you see that a list comprehension ...


8

How about a flip book? In a flip book each page represents the world as it exists at a moment in time. In our program the world is represented as some compound data structure (e.g. we have a banana which is in the hand of a gorilla which is in a tree which is in a jungle). Each subsequent page advances the story by slightly modifying the previous ...


5

No, there isn't any objective rule. If there were objective rules, someone could automate them and you'd be out of a job. Such decisions are always trade-offs between pressures that are pretty obvious in themselves, but have different relative strengths in different situations. So far, only (some) humans can properly judge such multidimensional optimization ...


4

Although there's a lot of truth in Simon's answer, I think there's also a much more practical reason. The nature of functional programming tends to generate a lot more parentheses than imperative programming, due to function chaining and composition. Those patterns of chaining and composition also usually happen to be able to be unambiguously represented ...


3

Both premises are wrong. These functional languages don't use space for function application. What they do is simply parse any expression that comes after a function as an argument. GHCi> f 3 4 GHCi> f(3) 4 GHCi> (f)3 4 course if you use neither a space nor parens then it normally won't work, simply because the expression isn't properly ...


3

Relationships. Friend: Given two people, a friend relationship follows these general laws Have good will towards each other Thinks each other are a friend to them (so the laws must be fulfilled by both members in this relationship) Enjoys spending time with each other Monoid: Given multiple items and a function that takes 2 of the items and returns 1, a ...


2

How can I write solid functional code that does not allow side effects even in languages that have mutable state and global variables? The simple answer is, do not use global or mutable variables, or just because you can mutate them does not mean you have to. Consider a class like this: class ImmutableClass { private int myImmutableField; ...


2

The simple answer is that the machinery for rows already existed in the typechecker, from the very first release of the PureScript compiler, so it made sense to reuse it to define the Eff monad. The only change was to allow rows to be parameterized by the kind of the types indexed by their labels. It certainly seems like labels are unnecessary, and they ...


2

I have never used PureScript, but the short answer is yes, effect labels are useful for modeling effects in a principled way. I'm not sure what your background is, so I don't know at what level to answer the question. Are you familiar with side effects, the downsides of their unrestricted use, functional programming, and why we try to avoid side effects in ...


1

Prefer pure functions and immutable variables/objects. Apart from that, keep in mind the limits and the conventions of the language you are using. Don't forget: Readability. Your colleagues will find your non-idiomatic code harder to understand Lack of tail call optimization Lack of laziness Lack of useful optimizations (ex. stream fusion) Lack of ...


1

Everything's a value, and you apply functions to values (which may be functions) to produce new values, preferably without producing any side effects.


1

FP offers a mental model for dealing with problems that is simpler than OOP's. Classes and objects are inherently more sophisticated than functions. There are a thousand ways to design a class interface. A function, on the other hand, is on the surface always just a function. What varies from an interface perspective are its arguments and output. This ...



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