Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  (no subject) (Dennis Raddle)
   2. Re:  (no subject) (Tony Morris)


----------------------------------------------------------------------

Message: 1
Date: Sun, 2 Sep 2012 20:32:13 -0700
From: Dennis Raddle <dennis.rad...@gmail.com>
Subject: [Haskell-beginners] (no subject)
To: Haskell Beginners <beginners@haskell.org>
Message-ID:
        <CAKxLvop6q48RC-YWhXS5vgGNu=zz8yz1dtvy56kj_cf_lef...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I wanted to run the map function from Data.Map, let's call it M.map, but
inside a monad transformer stack including the Error monad.

M.map has this type:

M.map :: (Ord k) => (a -> b)  -> Map k a  -> Map k b

However, I want to use a mapping function that has type

(Monad m) => a -> m b

(i.e. errors could be thrown during the computation, a log could be
written, etc)

I wrote the following. Any comments on this way of doing things?

mapMapM :: (Monad m, Ord k) => (a -> m b) -> Map k a -> m (Map k b)
mapMapM g mapIn = do
  let h (k,a) = do
        b <- g a
        return (k,b)
  y <- mapM h (M.toAscList mapIn)
  return $ M.fromAscList y
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120902/58b36638/attachment-0001.htm>

------------------------------

Message: 2
Date: Mon, 03 Sep 2012 13:34:42 +1000
From: Tony Morris <tonymor...@gmail.com>
Subject: Re: [Haskell-beginners] (no subject)
To: beginners@haskell.org
Message-ID: <50442552.7080...@gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On 03/09/12 13:32, Dennis Raddle wrote:
> I wanted to run the map function from Data.Map, let's call it M.map,
> but inside a monad transformer stack including the Error monad.
>
> M.map has this type:
>
> M.map :: (Ord k) => (a -> b)  -> Map k a  -> Map k b
>
> However, I want to use a mapping function that has type
>
> (Monad m) => a -> m b
>
> (i.e. errors could be thrown during the computation, a log could be
> written, etc)
>
> I wrote the following. Any comments on this way of doing things?
>
> mapMapM :: (Monad m, Ord k) => (a -> m b) -> Map k a -> m (Map k b)
> mapMapM g mapIn = do
>   let h (k,a) = do
>         b <- g a
>         return (k,b)
>   y <- mapM h (M.toAscList mapIn)
>   return $ M.fromAscList y
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

You probably want to look at Data.Traversable#traverse.


-- 
Tony Morris
http://tmorris.net/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120903/901b0b52/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 51, Issue 4
****************************************

Reply via email to