[Haskell-cafe] Coding conventions for Haskell?
Bas van Dijk
v.dijk.bas at gmail.com
Thu Sep 30 16:37:13 EDT 2010
Here are a few other styles I use:
* Unicode syntax and symbols
I use the UnicodeSyntax extension in all my projects. It allows you to
write nice Unicode syntax instead of the normal ASCII art. For
example: '→' instead of '->' and '∀' instead of 'forall'.
Additionally I'm a power-user of my brother's base-unicode-symbols
package[1]. I'm especially fond of the '∘' function composition
operator which you can use instead of '.'.
I believe UnicodeSyntax and symbols make code easier to read.
Although, it makes it slightly harder to write (see [2] for nice input
methods however).
* Use lambdas to group function arguments.
When I have a function which returns another function with a type that
is explicitly named, instead of listing all the arguments before the
=, I usually use a lambda to indicate that the function returns
another function. Take [3] for example:
readControl ∷ DeviceHandle → ControlAction ReadAction
readControl devHndl = \reqType reqRecipient request value index
→ \size timeout
→ ...
writeControl ∷ DeviceHandle → ControlAction WriteAction
writeControl devHndl = \reqType reqRecipient request value index
→ \input timeout
→ ...
where
type ControlAction α = RequestType
→ Recipient
→ Request
→ Value
→ Index
→ α
type ReadAction = Size → Timeout → IO (B.ByteString, TimedOut)
type WriteAction = B.ByteString → Timeout → IO (Size, TimedOut)
(I'm not sure if this has a negative effect on inlining tough.)
Regards,
Bas
[1] http://hackage.haskell.org/package/base-unicode-symbols
[2] http://haskell.org/haskellwiki/Unicode-symbols#Input_methods
[3] http://hackage.haskell.org/packages/archive/usb/0.6.0.1/doc/html/src/System-USB-Internal.html#readControl
More information about the Haskell-Cafe
mailing list