Domanda

When starting a new Haskell project which needs language features that are offered by both new and older extensions, which should I use? The new one or the old one? For example:

I incline towards the newer ones as they feel cleaner and they add more features to the language in a unified manner. However, the older ones are supported by more compilers, they're used in existing libraries and perhaps also better known among programmers.

Update: As mentioned in answers/comments, the "supersede" relationships above are not completely precise. However, I'm interested in (often occurring) cases when a task can be accomplished equally well by several extensions.

È stato utile?

Soluzione 2

In short, yes, and for the reasons you state: cleaner and clearer.

Occasionally I've come across places where there's a class better expressed as a multi-parameter type class with functional dependency because you can get more parametricity more simply that way, but usually an associated type family is a clearer and more flexible way of epressing it. Type families are much more intuitive to a functional programmer than functional dependencies.

GADTs have much cleaner, clearer syntax than existential quantification, with fewer conceptual hurdles, and it's easy to get the behaviour you want.

I'd recommend using the new stuff if you can, and the old ways if necessary. These lovely newer extensions could do with a higher profile.

Altri suggerimenti

"supersede" is very ambiguous here.

For language features that have semantics that overlap with other features, we can recognize a few cases:

  • some features generalize existing ones
  • some offer alternative approaches

In the case of more general features, there are risks and benefits. The generality can impact many other parts of the language, or be restricted. In the latter, choose the general case.

If it is a choice between alternative approaches, with no strict ordering, such as FDs or ATs, then it is harder to give general advice.

So, in summary, "no" , there's no obvious reason to use "new" things over "old" things, when it comes to language features. They don't sort that way.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top