Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/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. Re: randmomR produces only even values (Chadda? Fouch?) 2. Re: manipulating Map for music application (Chadda? Fouch?) 3. Re: manipulating Map for music application (Chadda? Fouch?) 4. is this not a better way ? data structure (Roelof Wobben) 5. Re: is this not a better way ? data structure (Alex Belanger) ---------------------------------------------------------------------- Message: 1 Date: Sat, 07 Nov 2015 17:17:23 +0000 From: Chadda? Fouch? <chaddai.fou...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] randmomR produces only even values Message-ID: <CANfjZRYakwM6THFV_xYpFV7ys=tYaHsb3qX_znx=q358big...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" The System.Random is just not very good, you should not use it if you need something fast or cryptographically secure... But as a first choice for just a few random numbers it's good enough and it was chosen specifically for its capability to split a generator into two, so that's probably what you should be using if you're going to do simulations in parallel with System.Random. Or use random seeds at least ! This is specifically an interaction between random*R* and mkStdGen with low seeds (random don't seem to have this particular flaw), since we're still using a pseudo-random generator, we ought to be pretty careful in the way we use it (those have always been touchy beasts) and this particular usage seems to be a bad counter-example of what to do with a PRNG. If we can improve System.Random to avoid this particular misbehavior we should but using a PRNG in this fashion and hoping for good randomness from the result is probably a bad idea in the first place. Le mer. 4 nov. 2015 ? 11:00, Dominic Steinitz <domi...@steinitz.org> a ?crit : > > http://article.gmane.org/gmane.comp.lang.haskell.beginners/15925 > > I do think this is a flaw and catches many people out despite apparently > being well documented. And it's something one probably wants e.g. to run > multiple Markov Chain Monte Carlo simulations in parallel. > > Some further information here: > https://github.com/haskell/random/issues/30#issuecomment-153647055 > > Dominic > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151107/882321c8/attachment-0001.html> ------------------------------ Message: 2 Date: Sat, 07 Nov 2015 17:41:38 +0000 From: Chadda? Fouch? <chaddai.fou...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] manipulating Map for music application Message-ID: <CANfjZRZnBRtDxPNSdxpwEgEvXPZr41jcy4W+FKjv_dpCV=9...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" This is a bit tricky but mapMaybeWithKey is clearly the tool for the job : > mapMaybeWithKey :: (k -> a -> Maybe <https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#t:Maybe> b) -> Map <https://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Lazy.html#t:Map> k a -> Map <https://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Lazy.html#t:Map> k b So : mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> Composition mapNotesMaybe f compo = mapMaybeWithKey go compo where go loc chords = mconcat . map (gogo loc) $ chords gogo loc chord = mconcat . map (fmap pure . f loc chord) $ chord This should work. -- Chadda? Le sam. 7 nov. 2015 ? 07:07, Dennis Raddle <dennis.rad...@gmail.com> a ?crit : > I have a Haskell program that computes music compositions. A composition > consists of sounds that happen at locations. A location is data type Loc. > At each location is a list of chords. A chord is data type Chord. Each > chord contains some chord-specific data and a list of notes. A note is data > type Note. > > So we have > > data Note = Note ... > data Chord = Chord ChordSpecificData [Note] > type Composition = Map Loc [Chord] > > I would like to write a few different functions that operate over all the > notes. > > The following function breaks out all the notes, tupling them with the > associated Locs and Chords: > compositionToList :: Composition -> [(Loc,Chord,Note)] > > The following function transforms Notes, keeping only the Just results. If > a Chord gets all its notes eliminated, that Chord is removed. If a Loc has > all its Chords removed, that Loc is removed from the Map. > mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition > -> Composition > > Any advice for concise code appreciated. > Dennis > > > What's a concise way of doing this? > > Another useful function would be used for mapping > > Dennis > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151107/1b1531df/attachment-0001.html> ------------------------------ Message: 3 Date: Sat, 07 Nov 2015 17:47:47 +0000 From: Chadda? Fouch? <chaddai.fou...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] manipulating Map for music application Message-ID: <canfjzraj02xwl5g_l1nb0ta7a9ard-n4sgqe2hm1qd+6tyb...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Ooops forgot that Chords are not just lists of Notes : mapNotesMaybe f compo = mapMaybeWithKey go compo where go loc chords = mconcat . map (fmap (:[]) . gogo loc) $ chords gogo loc chord@(Chord d notes) = fmap (Chord d) . mconcat . map (fmap (:[]) . f loc chord) $ notes Le sam. 7 nov. 2015 ? 18:41, Chadda? Fouch? <chaddai.fou...@gmail.com> a ?crit : > This is a bit tricky but mapMaybeWithKey is clearly the tool for the job : > > > mapMaybeWithKey :: (k -> a -> Maybe > <https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#t:Maybe> > b) -> Map > <https://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Lazy.html#t:Map> > k a -> Map > <https://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Map-Lazy.html#t:Map> > k b > > So : > > > mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition -> > Composition > mapNotesMaybe f compo = mapMaybeWithKey go compo > where > go loc chords = mconcat . map (gogo loc) $ chords > gogo loc chord = mconcat . map (fmap pure . f loc chord) $ chord > > This should work. > > -- > Chadda? > > > Le sam. 7 nov. 2015 ? 07:07, Dennis Raddle <dennis.rad...@gmail.com> a > ?crit : > >> I have a Haskell program that computes music compositions. A composition >> consists of sounds that happen at locations. A location is data type Loc. >> At each location is a list of chords. A chord is data type Chord. Each >> chord contains some chord-specific data and a list of notes. A note is data >> type Note. >> >> So we have >> >> data Note = Note ... >> data Chord = Chord ChordSpecificData [Note] >> type Composition = Map Loc [Chord] >> >> I would like to write a few different functions that operate over all the >> notes. >> >> The following function breaks out all the notes, tupling them with the >> associated Locs and Chords: >> compositionToList :: Composition -> [(Loc,Chord,Note)] >> >> The following function transforms Notes, keeping only the Just results. >> If a Chord gets all its notes eliminated, that Chord is removed. If a Loc >> has all its Chords removed, that Loc is removed from the Map. >> mapNotesMaybe :: (Loc -> Chord -> Note -> Maybe Note) -> Composition >> -> Composition >> >> Any advice for concise code appreciated. >> Dennis >> >> >> What's a concise way of doing this? >> >> Another useful function would be used for mapping >> >> Dennis >> >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151107/17c95e8a/attachment-0001.html> ------------------------------ Message: 4 Date: Sat, 7 Nov 2015 22:56:43 +0100 From: Roelof Wobben <r.wob...@home.nl> To: beginners@haskell.org Subject: [Haskell-beginners] is this not a better way ? data structure Message-ID: <563e739b.9080...@home.nl> Content-Type: text/plain; charset=utf-8; format=flowed Hello, In the book there is a example of this data-structure. data Shape = Circle float float | Rectangle float float Now I have to change it to add a center point. But I wonder if this is not a better way to describe it Data Schape = Circle Radius | Rectangle Width Height Type Radius = Float type Width = Float type Height = Float Roelof ------------------------------ Message: 5 Date: Sat, 7 Nov 2015 17:03:11 -0500 From: Alex Belanger <i.caught....@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] is this not a better way ? data structure Message-ID: <cadsky2x9rjonnafefe4yupc3t_j3cgn1fw6+gnq-xk0uhbt...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I feel the latter example serves only documentation purposes. Maybe describe what those floats are in the former example and you can ignore the extra type aliases entirely. Introducing a new concern for your module/application when it appears only once might just add extra complexity. Of course, as the codebase grows and this datatype evolves, you'll probably want to go that route, but until then, I think it's preemptively unecessery. - nitrix On Nov 7, 2015 4:56 PM, "Roelof Wobben" <r.wob...@home.nl> wrote: > Hello, > > In the book there is a example of this data-structure. > > data Shape = Circle float float > | Rectangle float float > > Now I have to change it to add a center point. > > But I wonder if this is not a better way to describe it > > Data Schape = Circle Radius > | Rectangle Width Height > > Type Radius = Float > type Width = Float > type Height = Float > > Roelof > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151107/5482def9/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 89, Issue 9 ****************************************