xzhu
xzhu

Reputation: 5755

How do I implicitly import commonly used modules?

Recently I've been writing a lot of scripts in Haskell. It's quite an enjoyable experience as it is one of the most concise languages I've ever touched.

One thing that bothers me a lot though, is that I have to type in the same imports for every script I write, and there's a set of modules I use almost everytime, like

import Control.Monad as MO
import Data.ByteString.Lazy as BS
import Data.Char as CH
import Data.Csv as C
import Data.Csv.Streaming as CS
import Data.Foldable as FOLD
import Data.Functor as F
import Data.List as L
import Data.List.Split as LS
import Data.Text.Lazy as T
import Data.Text.Lazy.IO as TI
import Data.Vector as V
import Debug.Trace as TR
import Prelude as P

I mean I could copy and paste them every time, but is there a way I can make these tedious imports implicit? Just like how Prelude is imported implicitly?

Upvotes: 7

Views: 252

Answers (1)

dfeuer
dfeuer

Reputation: 48580

One option for some purposes is to write one or more "kitchen sink" modules for your own use and just import that every time. Unfortunately, that doesn't seem to do much good when it comes to named or qualified imports. Another option is to use {-# LANGUAGE CPP #-} to #include some stock header pieces.

However, I wouldn't particularly recommend any of these options. Just keep a "stock template" around with your favorite GHC extensions and module imports, and teach your text editor to use it. Don't forget to prune away the stuff you don't actually need.

Upvotes: 13

Related Questions