[Haskell-cafe] Open unqualified imports
Dan Doel
dan.doel at gmail.com
Fri Jan 16 18:18:53 EST 2009
On Friday 16 January 2009 9:42:46 am eyal.lotem at gmail.com wrote:
> I think currently many modules are designed to be imported
> unqualified, and this is unfortunate. Haskell' libraries can fix
> this. For example, the various Monadic counterparts such as mapM,
> replicateM, etc could do without the "M" in their names, and one could
> use:
>
> import qualified Control.Monad as M
>
> M.for
> M.map
I don't think I can fully agree with this. The fooM functions are so named
because their type is different in a fairly predictable way from ordinary foo
functions. And there are, in fact, two different functions that could lay
claim to M.map. One is named mapM, of course, but the other is liftM:
liftM :: Monad m => (a -> b) -> m a -> m b
Which is an implementation of the ordinary map using the methods of Monad.
Similarly, Data.Traversable has two functions:
mapM :: Monad m => (a -> m b) -> t a -> m (t b)
fmapDefault :: Traversable t => (a -> b) -> t a -> t b
So, do we end up with T.map is a monadic map, but T.mapDefault is an ordinary
Functor map using the Traversable methods. There are also mapAccumL and
mapAccumR, but those don't allow monadic functions like T.map, just pure
functions like T.mapDefault (although, secretly it's T.map specialized to the
state monad).
Anyhow, if you have some easy way to view the types of these functions, that
clears up their use quite a bit. However, the naming scheme is not purely due
to "this is map from the Monad module we're going to import unqualified."
There is some method to it.
-- Dan
More information about the Haskell-Cafe
mailing list