Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Mapping list over datatype using Traversable and State
monad. (Dmitriy Matrosov)
2. Re: Mapping list over datatype using Traversable and State
monad. (Dmitriy Matrosov)
3. Picking a random element from a Map (Harald B?geholz)
4. Re: Picking a random element from a Map (Daniel Trstenjak)
----------------------------------------------------------------------
Message: 1
Date: Tue, 25 Sep 2012 17:42:00 +0400
From: Dmitriy Matrosov <[email protected]>
Subject: Re: [Haskell-beginners] Mapping list over datatype using
Traversable and State monad.
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Mon, 24 Sep 2012 16:35:45 -0400
Brent Yorgey <[email protected]> wrote:
> My one suggestion might be to abstract out the "zippy apply" pattern,
> like so:
>
> zipApp :: Traversable f => [a -> b] -> f a -> f b
> zipApp fs = fst . flip runState fs . T.mapM f
> where
> f x = ... etc, same as above
>
> Then inlineSeps g = zipApp (id : repeat g), and you can reuse zipApp
> for other things.
Thanks! This is nicer, indeed. Perhaps, the last piece i'm missed for :)
------------------------------
Message: 2
Date: Tue, 25 Sep 2012 23:06:26 +0400
From: Dmitriy Matrosov <[email protected]>
Subject: Re: [Haskell-beginners] Mapping list over datatype using
Traversable and State monad.
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
I have one more question.
Also i need to zipApp list to part of Line: either to only first list
("ordered" elements) or to only second ("other" elements). I have implemented
this using Monoid:
import Data.Monoid
instance Monoid (Line a) where
mempty = Line [] []
(Line xs ys) `mappend` (Line xs' ys')
= Line (xs `mappend` xs') (ys `mappend` ys')
onlyOrdered :: Line a -> Line a
onlyOrdered (Line xs ys) = Line xs []
onlyOthers :: Line a -> Line a
onlyOthers (Line xs ys) = Line [] ys
and function looks like
inlineToOrdered :: (a -> a) -> Line a -> Line a
inlineToOrdered g = mappend
<$> zipApp (id : repeat g) . onlyOrdered
<*> onlyOthers
It works as well, but is this solution good? Or there is some better way to
limit "scope" of function application to only part of datatype?
------------------------------
Message: 3
Date: Wed, 26 Sep 2012 09:33:26 +0200
From: Harald B?geholz <[email protected]>
Subject: [Haskell-beginners] Picking a random element from a Map
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Hi,
how do I (quickly) pick a random element from a `Data.Map.Map`?
Right now I am using `head $ Map.keys p` to get the first element, but
I'd like to replace this by a random element.
I know I have to drag around the state of the random generator
somewhere, but if I have one I am wondering what's the best way to use
one to take a pick from the map.
Thanks
--
Harald B?geholz <[email protected]> (PGP key available from servers)
Redaktion c't Tel.: +49 511 5352-300 Fax: +49 511 5352-417
http://www.ct.de/
int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;
main(){for(;b=c,c-=14;i=printf("%04d",e+d/a),e=d%a)
while(g=--b*2)d=h*b+a*(i?f[b]:a/5),h=d/--g,f[b]=d%g;}
(Arndt/Haenel)
Affe Apfel Vergaser
/* Heise Zeitschriften Verlag GmbH & Co. KG * Karl-Wiechert-Allee 10 *
30625 Hannover * Registergericht: Amtsgericht Hannover HRA 26709 *
Pers?nlich haftende Gesellschafterin: Heise Zeitschriften Verlag *
Gesch?ftsf?hrung GmbH * Registergericht: Amtsgericht Hannover, HRB
60405 * Gesch?ftsf?hrer: Ansgar Heise, Dr. Alfons Schr?der */
------------------------------
Message: 4
Date: Wed, 26 Sep 2012 10:09:28 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] Picking a random element from a Map
To: Harald B?geholz <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <20120926080928.GA5012@machine>
Content-Type: text/plain; charset=us-ascii
Hi Harald,
> how do I (quickly) pick a random element from a `Data.Map.Map`?
>
> Right now I am using `head $ Map.keys p` to get the first element, but
> I'd like to replace this by a random element.
>
> I know I have to drag around the state of the random generator
> somewhere, but if I have one I am wondering what's the best way to use
> one to take a pick from the map.
M.keys map !! randomValue `mod` M.size map
But if you need a high performance solution than it's more appropriate
to put the values into a Data.Vector and indexing into it.
Greetings,
Daniel
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 51, Issue 38
*****************************************