A language extension is an optional compiler-supported addition that changes Haskell's default syntax or behavior. Extensions can apply globally through compiler flags or locally through a module pragma. section 6.2.2
Language extensions support practical programming tasks such as:
- Enabling ScopedTypeVariables so a type variable introduced by forall can be reused consistently across a function declaration. section 6.2.2
- Using NamedFieldPuns to access selected record fields without assigning each field a new name. section 7.3
- Using RecordWildCards to make record fields available by name, avoiding a long list of field bindings. section 7.3
Enabling ScopedTypeVariables
Place the pragma at the beginning of a module:\n\n{-# LANGUAGE ScopedTypeVariables #-}\n\nmodule Graph (...) where\n\nWith the extension enabled, an explicit forall introduces lexically scoped type variables. For example, f :: forall a. a -> a allows the annotation (x :: a) inside the function's where binding to refer to the same a.
Listing 7.7 Functions to compute the number of rows and columns in a CSV file
numberOfRows :: Csv -> Int
numberOfRows Csv {..} = #1
case csvColumns of
[] -> 0 #2
(x : _) -> length x #3
numberOfColumns :: Csv -> Int
numberOfColumns Csv {..} = length csvColumns #4
A complete CSV example shows RecordWildCards in functions that compute row and column counts. section 7.3
