Hot answers tagged

46 votes

What are the functional equivalents of imperative break statements and other loop checks?

The closest equivalent to looping over an array in most functional languages is a fold function, i.e. a function that calls a user-specified function for each value of the array, passing an ...
Jules's user avatar
  • 17.6k
34 votes

Using a "strong" type system in the real world, say, for large-scale web-apps?

I'll give a short answer due to my lack of time at the moment, but I'm currently working on two big projects (> 100.000 LOC in Haskell) - flowbox.io and luna-lang.org. We use Haskell for all the parts,...
danilo2's user avatar
  • 669
34 votes
Accepted

Could Hindley-Milner inference work for the Go language?

The Hindley-Milner type inference is used for Hindley-Milner type systems, a restriction of System-F type systems. The interesting feature of HM type systems is that they have parametric polymorphism (...
amon's user avatar
  • 133k
33 votes

What are the functional equivalents of imperative break statements and other loop checks?

You could easily convert it to recursion. And it has nice tail-optimized recursive call. Pseudocode : public int doSomeCalc(int[] array) { return doSomeCalcInner(array, 0); } public int ...
Euphoric's user avatar
  • 36.9k
33 votes
Accepted

Definition of "functor"; Haskell vs. C++

The two meanings are unrelated. The Haskell community (and really the Functional Programming community in general, and even the general programming community beyond FP) uses the term Functor in the ...
Jörg W Mittag's user avatar
30 votes

Does it make sense to use the term "Space Leak" with regard to Java?

No. Pretty much all modern programs use more space than is necessary. If your Java program is keeping objects alive when the programmer thinks it should be eligible for collection, it is a memory ...
Telastyn's user avatar
  • 109k
21 votes
Accepted

How does "repeat x = x:repeat x" return a list in Haskell?

Probably your confusion comes from the fact that you are used to eager evaluation, whereas Haskell uses lazy evaluation. For example, if you were to use the definition repeat' x = x : repeat' x to ...
Giorgio's user avatar
  • 19.5k
20 votes

Definition of "functor"; Haskell vs. C++

The word "functor" has been around for a very long time, and modern usage stems from analytic philosophy, especially topics related to logic and language. The first usage I found was due to ...
Levi Pearson's user avatar
19 votes
Accepted

What is the reasoning behind making non-determinism a feature of Haskell?

While it is true that both aspects cited in the questions appear as forms of non-determinism, they are indeed quite different both in how they work and in their goals. Hence any answer has to be ...
gigabytes's user avatar
  • 342
18 votes
Accepted

Why do textbooks use pseudocode rather than real languages?

No. The point of pseudo-code is that it doesn't have to compile. I can quickly gloss over irrelevant details. In contrast, even languages that look like pseudocode at the first glance can have very ...
amon's user avatar
  • 133k
18 votes
Accepted

Functional programming - what to learn and who uses it

Since you write that you're a .NET developer and you don't even mention F#, odds are that you're a C# developer. In that case, I'd strongly suggest that you learn F# first. It's another .NET language, ...
Mark Seemann's user avatar
  • 3,860
17 votes

Using a "strong" type system in the real world, say, for large-scale web-apps?

Well, weak vs. strong typing is pretty vaguely defined. Further, since closest there is to a general use of 'strong typing' is to refer things that make it difficult to cast types, that leaves nothing ...
Steven Armstrong's user avatar
16 votes
Accepted

Does it make sense to use the term "Space Leak" with regard to Java?

Does it make sense to use the term “Space Leak” with regard to Java? Frankly, no. While the term is well-founded, and it is (or may be) understood by the Haskell community, the distinction between "...
Stephen C's user avatar
  • 25.2k
14 votes

What are the functional equivalents of imperative break statements and other loop checks?

I really like Jules' answer, but I wanted to additionally point out something people often miss about lazy functional programming, which is that everything doesn't have to be "inside the loop." For ...
Karl Bielefeldt's user avatar
13 votes

What is the benefit of short readable code if you only see functions and classes on the outside?

how exactly the methods and properties were written you do not care about, as long as they do what they promise to do. Exactly. But as soon as they don't do what they promise to do, you have to go ...
Arseni Mourzenko's user avatar
11 votes
Accepted

Should I use functions based on Applicatives or Monads?

For both efficiency and generality, you should typically prefer the most general operators. So you should use Applicative operators in preference to Monad, and Alternative to MonadPlus. The ...
Derek Elkins left SE's user avatar
10 votes

Using a "strong" type system in the real world, say, for large-scale web-apps?

I just started working on the core team of a large platform written in Scala. You can look at successful open source applications, like Scalatra, Play, or Slick to see how they handle some of your ...
Karl Bielefeldt's user avatar
10 votes

Why do textbooks use pseudocode rather than real languages?

No. The entire purpose of pseudo-code is to abstract away the details and complexities of individual languages so that you focus on what the program's supposed to do, rather than how it does it. With ...
Lightness Races in Orbit's user avatar
10 votes
Accepted

Precisely define "what to solve" and "how to solve" corollary in functional and imperative programming respectively

Isn't above code snippet is just different way of saying "how to solve" problem ? Yes. In the end, computer science is invariably about computing so you're always talking about "how to solve" a ...
Telastyn's user avatar
  • 109k
9 votes
Accepted

Why isn't Bounded a subclass of Enum in Haskell

One practical example I like comes from the world of programming languages: the set of types in an OO system is bounded and discrete but not enumerable, and partially ordered but not totally ordered. ...
Benjamin Hodgson's user avatar
9 votes
Accepted

What is the difference between Applicative and Generative Modules, and Type Classes?

Since both are in OCaml, We can explore the difference between generative and applicative functors easily: module type S = sig type t end module M = struct type t = int end (* An Applicative functor....
Drup's user avatar
  • 204
8 votes

Is return-type-(only)-polymorphism in Haskell a good thing?

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 ...
Derek Elkins left SE's user avatar
8 votes
Accepted

Why (or why not) are existential types considered bad practice in functional programming?

Existential types are not really considered bad practice in functional programming. I think what's tripping you up is that one of the most commonly cited uses for existentials is the existential ...
sacundim's user avatar
  • 4,758
8 votes

Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?

Given a closed set (fixed number of elements) S with elements {a..z} and a binary operator *: There is a single identity element i such that: forall x in S: i * x = x = x * i The operator is ...
Jimmy Hoffa's user avatar
8 votes
Accepted

What is the purpose of wrapped values in Haskell?

Java's Optional is essentially equivalent to Haskell's Maybe monad, so that's a good starting place for understanding how these "wrapped values" behave. Functors, Applicatives and Monads are ways of ...
KChaloux's user avatar
  • 5,783
8 votes

Using a "strong" type system in the real world, say, for large-scale web-apps?

While not a direct answer (since I haven't worked on +30.000 LOC code bases in haskell yet :(..), I implore you to check out https://www.fpcomplete.com/business/resources/case-studies/ which features ...
Tehnix's user avatar
  • 189
8 votes

Can I use maybe on multiple inputs in Haskell?

The code is morally correct but lacking in a few places. The conditional stuff is actually fine, the part that's tripping you up is Indicating that you want a tuple Constructing a Maybe value First ...
daniel gratzer's user avatar
8 votes

Difference between Python classes and Haskell typeclasses

One difference: In Python, you can define a subclass MySubclass of MyClass, and then you can freely add objects of MyClass with objects of MySubclass. Haskell tends to avoid subtyping: if you have a ...
Daniel Díaz Carrete's user avatar
8 votes

What is the difference between Haskell's type classes and Go's interfaces?

There are several differences Haskell typeclasses are nominatively typed -- you have to declare that Maybe is a Monad. Go interfaces are structurally typed: if circle declares area() float64 and so ...
walpen's user avatar
  • 3,231

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