Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implicitly import commonly used modules?

Tags:

haskell

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?

like image 980
xzhu Avatar asked Oct 02 '15 03:10

xzhu


People also ask

How do you automatically import a module in Python?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. In the Python section, configure automatic imports: Select Show import popup to automatically display an import popup when tying the name of a class that lacks an import statement.

How do you dynamically import a module using a function?

To load dynamically a module call import(path) as a function with an argument indicating the specifier (aka path) to a module. const module = await import(path) returns a promise that resolves to an object containing the components of the imported module. } = await import(path);

What are the three ways to import modules in Python?

So there's four different ways to import: Import the whole module using its original name: pycon import random. Import specific things from the module: pycon from random import choice, randint. Import the whole module and rename it, usually using a shorter variable name: pycon import pandas as pd.

How do I import a specific module in Python?

You need to use the import keyword along with the desired module name. When interpreter comes across an import statement, it imports the module to your current program. You can use the functions inside a module by using a dot(.) operator along with the module name.


1 Answers

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.

like image 98
dfeuer Avatar answered Oct 29 '22 12:10

dfeuer