Scrap your qualified import clutter
Most of the time we find ourselves following this pattern in Haskell:
import Data.Text (Text)
import qualified Data.Text as Text
import Data.ByteString (ByteString)
import qualified Data.ByteString as ByteString
require adds a new keyword that abstracts this. The former code snippet can be reduced to
require Data.Text
require Data.ByteString
Here, the last part of the module is converted to a qualified alias, and a type corresponding to it:
require Data.Text
Will import Data.Text
qualified as Text
and the Text
type.
There are more options, you can check them out in the require docs.
How to use require
- Add
require
to your project dependencies - Set the required GHC option:
ghc-options: -F -pgmF requirepp
in your project configuration file.{-# OPTIONS_GHC -F -pgmF requirepp #-}
if you want it per-file.