[Haskell-cafe] Coding conventions for Haskell?
Bas van Dijk
v.dijk.bas at gmail.com
Thu Sep 30 15:02:07 EDT 2010
On Thu, Sep 30, 2010 at 5:15 PM, Christopher Done
<chrisdone at googlemail.com> wrote:
> ... One thing that makes figuring out a code base hard is when the
> code doesn't have explicit imports. Sometimes I can load the code in
> GHCi and inspect the symbols manually, sometimes I can't. If the
> import list explicitly said where stuff came from I wouldn't have to
> deal with this.
Indeed. I strictly use this style in all my projects. See the
following for example:
I see it as a service to my readers. In order to find out where a
symbol is coming from they only need to scroll up and look it up in
the import list. Note that for further convenience I group the imports
by package so they don't need to figure out which package exports what
I try to follow this style very strictly. I'm even using
NoImplicitPrelude to not miss any implicitly imported symbol. I also
import symbols from their defining module instead as from the Prelude.
For example, instead of importing fmap from the Prelude I import it
from Data.Functor. This ensures that when a reader looks up a symbol
she doesn't need to skim through a lot of unrelated code.
To be honest, there are cases where I violate my own rule. In the USB
module for example, I import Bindings.Libusb without explicitly
listing the used symbols. In this case I think it's justified because
I pretty much use all the symbols from that module and all symbols are
prefixed with 'c'libusb_' which clearly indicates where they are
Note that, although I don't use it myself, the GHC flag:
-ddump-minimal-imports can help you with this style:
More information about the Haskell-Cafe