Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use GHC Haskell extensions or not?

Tags:

haskell

ghc

As I am learning Haskell, I see that there is a lot of language extensions used in real life code. As a beginner, should I learn to use them, or should I avoid them at all cost? I see that it breaks compatibility with Haskell 98 and limits code to pretty much GHC only. However, if I browse packages on Hackage, I see that most of them are GHC-only anyway.

So, what is an attitude of community towards using language extensions?

And if use of extensions is OK, how can I distinguish extensions which I can use “safely” (those which are likely to become part of the next Haskell standard) from those which are mostly “experimental”? For example, I suppose that -XDisambiguateRecordFields is nice and useful, but is it likely to be supported in the future?

like image 538
sastanin Avatar asked Apr 29 '09 10:04

sastanin


2 Answers

There are some GHC extensions that are too good to live without. Among my favorites are

  • Multiparameter type classes
  • Scoped type variables
  • Higher-rank types
  • Generalized algebraic data types (GADTs)

Of these the really essential one is multiparameter type classes.

Some GHC extensions are very speculative and experimental, and you may want to use with caution. A good way to identify a stable and trusted extension is to see if it is slated for inclusion in Haskell Prime, which is hoped to be the successor the Haskell 98.

I second Don Stewart's suggestion that every extension should be marked using the LANGUAGE pragma in the source file. Don't enable extensions using command-line options.

like image 179
Norman Ramsey Avatar answered Oct 04 '22 03:10

Norman Ramsey


Yes, use extensions as appropriate.

But be sure to enable them intentionally -- only when you decide you need them. Do this on a per-module basis via {-# LANGUAGE Rank2Types #-} (for example).

like image 35
Don Stewart Avatar answered Oct 04 '22 05:10

Don Stewart