Hot answers tagged

5

I think you are creating a bit of a false dichotomy here. Haskell has monad comprehensions built into the language. One reason for that is the use of monads for imperative-style I/O. Therefore, the designers of Haskell decided to make it look mostly like a code block in a generic C-style language, complete with curly braces, semicolons and even return. The ...


4

There's multiple reasons: Some functions will return tuples and it's useful to compose such functions directly with other functions that accept tuples. Often when values are bundled in a tuple they're conceptually one unit, i.e. you almost always pass all of them together. In other words, there's certain functions you wouldn't curry often. It's trivial to ...


2

I don't have much background on why Scala designers made that particular wording choice, but in F#, local "do notation" equivalent is called a "computation expression". The reasoning behind that word choice is one of PR and marketing rather than any concrete technical reason. Haskell has a hard-earned reputation of being a language for academics, rocket ...


2

In a pure language like Haskell, all data is immutable and no existing data structures can be changed in any way Actually that is not generally true. Pure languages use non-strict (lazy) evaluation so the evaluation of potentially all subexpressions is deferred. Unevaluated expressions are generally heap allocated as a "thunk". When required the ...


1

The code you have there is about as far from functional as could possibly be. The entire function is built around a side-effecting loop which mutates a value. Here's the trivial functional implementation of a map operation: Array.prototype.map = function (fn) { const [first, ...rest] = this; return this.length === 0 ? [] : ...


1

In the spirit of Conal, break it into smaller simpler operations. In this case, asum from Data.Foldable does the main part. tryFunction fs x = asum (map ($ x) fs) Alternatively, a la Jimmy Hoffa's reply you can use the Monoid instance for (->) but then you need a Monoid instance for Maybe and the standard one doesn't do what you want. You want First ...


1

The answer to your question is the "implicit currying" option. However, there are times where you would use the second option. In Haskell, for performance, you may want to share some work in the partially applied result. (Note, nothing in the Report guarantees this sharing or precludes the compiler from lifting out the work itself. In practice, GHC ...


1

I really wish the term "return type polymorphism" was never created. It encourages a misunderstanding of what is happening. Suffice it to say, while eliminating "return type polymorphism" would be an extremely ad-hoc and expressiveness killing change, it wouldn't even remotely resolve the issues brought up in the question. The return type is in no way ...


1

I primarily work in functional code now, and from that perspective it seems blindingly obvious. Side effects create a huge mental burden on programmers trying to read and understand code. You don't notice that burden until you are free from it for a while, then suddenly have to read code with side effects again. Consider this simple example: val foo = 42 ...



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