[Haskell-beginners] Syntactic sugar to insert into a Map?
markus.l2ll at gmail.com
Tue Jul 23 05:49:51 CEST 2013
I think given that integers are converted to fromInteger x and that
strings can be overloaded you could implement something like this with
a state or a writer monad:
mySet = do
To do this you'll need to implement the appropriate classes. But I
guess it's more a hack towards getting what you want than to being
true to what a monad is.
On Mon, Jul 22, 2013 at 3:06 AM, Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> On 21 July 2013 17:23, martin <martin.drautzburg at web.de> wrote:
>> I just want to insert several key/value pairs, something like
>> insert key1 val1
>> insert key2 val2
>> return theMap
> If you really want this syntax, what about using the writer monad:
> import Control.Monad.Writer
> import qualified Data.Map as M
> m = execWriter $ do
> insert 1 "foo"
> insert 2 "bar"
> where insert k v = tell (M.singleton k v)
> -- m = fromList [(1,"foo"),(2,"bar")]
> Hope this helps,
> Beginners mailing list
> Beginners at haskell.org
More information about the Beginners