Skip to content

Instantly share code, notes, and snippets.

@nkpart
Created January 27, 2015 22:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkpart/f35040bc25686d9f46b5 to your computer and use it in GitHub Desktop.
Save nkpart/f35040bc25686d9f46b5 to your computer and use it in GitHub Desktop.
Explaining traverse/mapM
∴ ghci
:iGHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :i traverse
Top level:
Not in scope: ‘traverse’
Perhaps you meant ‘reverse’ (imported from Prelude)
Prelude> import Data.Traversable
Prelude Data.Traversable> :i traverse
class (Functor t, Data.Foldable.Foldable t) =>
Traversable (t :: * -> *) where
traverse ::
Control.Applicative.Applicative f => (a -> f b) -> t a -> f (t b)
...
-- Defined in ‘Data.Traversable’
Prelude Data.Traversable> :i mapM
Top level:
Ambiguous occurrence ‘mapM’
It could refer to either ‘Data.Traversable.mapM’,
imported from ‘Data.Traversable’
or ‘Prelude.mapM’,
imported from ‘Prelude’ (and originally defined in ‘Control.Monad’)
Prelude Data.Traversable> :i Prelude.mapM
Prelude.mapM :: Monad m => (a -> m b) -> [a] -> m [b]
-- Defined in ‘Control.Monad’
Prelude Data.Traversable> :t traverse
traverse
:: (Traversable t, Control.Applicative.Applicative f) =>
(a -> f b) -> t a -> f (t b)
Prelude Data.Traversable> :t (traverse :: Monad m => (a -> m b) -> [a] -> m [b])
<interactive>:1:2:
Could not deduce (Control.Applicative.Applicative m1)
arising from a use of ‘traverse’
from the context (Monad m)
bound by the inferred type of
it :: Monad m => (a -> m b) -> [a] -> m [b]
at Top level
or from (Monad m1)
bound by an expression type signature:
Monad m1 => (a1 -> m1 b1) -> [a1] -> m1 [b1]
at <interactive>:1:2-50
Possible fix:
add (Control.Applicative.Applicative m1) to the context of
an expression type signature:
Monad m1 => (a1 -> m1 b1) -> [a1] -> m1 [b1]
or the inferred type of it :: Monad m => (a -> m b) -> [a] -> m [b]
In the expression:
(traverse :: Monad m => (a -> m b) -> [a] -> m [b])
Prelude Data.Traversable> :t (traverse :: Applicative m) => (a -> m b) -> [a] -> m [b])
<interactive>:1:29: parse error on input ‘=>’
Prelude Data.Traversable> :t (traverse :: Applicative m => (a -> m b) -> [a] -> m [b])
<interactive>:1:14:
Not in scope: type constructor or class ‘Applicative’
Prelude Data.Traversable> import Control.Applicative
Prelude Data.Traversable Control.Applicative> :t (traverse :: Applicative m => (a -> m b) -> [a] -> m [b])
(traverse :: Applicative m => (a -> m b) -> [a] -> m [b])
:: Applicative m => (a -> m b) -> [a] -> m [b]
Prelude Data.Traversable Control.Applicative>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment