Send Beginners mailing list submissions to
        [email protected]

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
        [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:  is this not a better way ? data structure (Roelof Wobben)
   2. Re:  manipulating Map for music application (Dennis Raddle)
   3.  Why does floor not consider its argument an      Integral?
      (Jeffrey Brown)
   4. Re:  Why does floor not consider its argument an  Integral?
      (Jeffrey Brown)


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

Message: 1
Date: Sat, 7 Nov 2015 23:32:29 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] is this not a better way ? data
        structure
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151107/a016a779/attachment-0001.html>

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

Message: 2
Date: Sat, 7 Nov 2015 15:01:09 -0800
From: Dennis Raddle <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] manipulating Map for music
        application
Message-ID:
        <cakxlvoo0mdszufzhfrcyfdceahbdmkoy-2yqnw_kd8uzzw9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks! I'm a Haskell beginner and will relish the opportunity to learn
more by studying your code.

On Sat, Nov 7, 2015 at 9:47 AM, Chadda? Fouch? <[email protected]>
wrote:

> 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? <[email protected]> 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 <[email protected]> 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
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> 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/dbec8808/attachment-0001.html>

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

Message: 3
Date: Sat, 7 Nov 2015 22:14:58 -0800
From: Jeffrey Brown <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Subject: [Haskell-beginners] Why does floor not consider its argument
        an      Integral?
Message-ID:
        <caec4ma3pajjfvdm2r+aqktawjgkcbm2-w6hb5ztcuemeqx5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Tidal [1] defines these data types:

    type Time = Rational
    type Arc = (Time, Time)

I want to write a function "splitMultiCycArc" which divides an Arc into
mostly-integer segments, so that, for instance,

    splitMultiCycArc (0,1)   = [(0,1)]
    splitMultiCycArc (0,2)   = [(0,1),(1,2)]
    splitMultiCycArc (0,3)   = [(0,1),(1,2),(2,3)]
    splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)]
    splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)]

I thought I had solved the problem with this code:

    splitMultiCycArc:: Arc -> [Arc]
    splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in
      if      b <= a           then []
      else if b <= ceiling_ish then [(a,b)]
      else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b)

When I try to load that, I get this single error:

    > :reload
    [12 of 13] Compiling Sound.Tidal.JBB  ( Sound/Tidal/JBB.hs, interpreted
)

    Sound/Tidal/JBB.hs:16:44:
        No instance for (Integral Time) arising from a use of ?floor?
        In the first argument of ?(+)?, namely ?floor a?
        In the expression: floor a + 1
        In an equation for ?ceiling_ish?: ceiling_ish = floor a + 1
    Failed, modules loaded: Sound.Tidal.Strategies, Sound.Tidal.Dirt,
Sound.Tidal.Pattern, Sound.Tidal.Stream, Sound.Tidal.Parse,
Sound.Tidal.Tempo, Sound.Tidal.Time, Sound.Tidal.Utils,
Sound.Tidal.SuperCollider, Sound.Tidal.Params, Sound.Tidal.Transition.
    >

And yet under other conditions, "floor" is perfectly happy operating on a
Time value:

    > let a = (1%2,1) :: Arc
    > floor (fst a) + 1
    1
    >

[1] https://hackage.haskell.org/package/tidal


-- 
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151107/8143a3d8/attachment-0001.html>

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

Message: 4
Date: Sat, 7 Nov 2015 23:10:17 -0800
From: Jeffrey Brown <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Subject: Re: [Haskell-beginners] Why does floor not consider its
        argument an     Integral?
Message-ID:
        <caec4ma0y8y-h9+r3jznobfu5molz1erxewqhw7ihvtwqztt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I solved it. I was misreading the error report as being about the input to
floor, when the problem was the output of it. This code works:

splitArcAtIntegers:: Arc -> [Arc]
splitArcAtIntegers (a,b) = let
    ceiling_ish = fromInteger $ (floor a) + 1
  in if      b <= a           then []
     else if b <= ceiling_ish then [(a,b)]
     else (a,ceiling_ish) : splitArcAtIntegers (ceiling_ish,b)


On Sat, Nov 7, 2015 at 10:14 PM, Jeffrey Brown <[email protected]>
wrote:

> Tidal [1] defines these data types:
>
>     type Time = Rational
>     type Arc = (Time, Time)
>
> I want to write a function "splitMultiCycArc" which divides an Arc into
> mostly-integer segments, so that, for instance,
>
>     splitMultiCycArc (0,1)   = [(0,1)]
>     splitMultiCycArc (0,2)   = [(0,1),(1,2)]
>     splitMultiCycArc (0,3)   = [(0,1),(1,2),(2,3)]
>     splitMultiCycArc (1%2,2) = [(1%2,1),(1,2)]
>     splitMultiCycArc (1,5%2) = [(1,2),(2,5%2)]
>
> I thought I had solved the problem with this code:
>
>     splitMultiCycArc:: Arc -> [Arc]
>     splitMultiCycArc (a,b) = let ceiling_ish = floor a + 1 in
>       if      b <= a           then []
>       else if b <= ceiling_ish then [(a,b)]
>       else (a,ceiling_ish) : splitMultiCycArc (ceiling_ish,b)
>
> When I try to load that, I get this single error:
>
>     > :reload
>     [12 of 13] Compiling Sound.Tidal.JBB  ( Sound/Tidal/JBB.hs,
> interpreted )
>
>     Sound/Tidal/JBB.hs:16:44:
>         No instance for (Integral Time) arising from a use of ?floor?
>         In the first argument of ?(+)?, namely ?floor a?
>         In the expression: floor a + 1
>         In an equation for ?ceiling_ish?: ceiling_ish = floor a + 1
>     Failed, modules loaded: Sound.Tidal.Strategies, Sound.Tidal.Dirt,
> Sound.Tidal.Pattern, Sound.Tidal.Stream, Sound.Tidal.Parse,
> Sound.Tidal.Tempo, Sound.Tidal.Time, Sound.Tidal.Utils,
> Sound.Tidal.SuperCollider, Sound.Tidal.Params, Sound.Tidal.Transition.
>     >
>
> And yet under other conditions, "floor" is perfectly happy operating on a
> Time value:
>
>     > let a = (1%2,1) :: Arc
>     > floor (fst a) + 1
>     1
>     >
>
> [1] https://hackage.haskell.org/package/tidal
>
>
> --
> Jeffrey Benjamin Brown
>



-- 
Jeffrey Benjamin Brown
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151107/2695ae03/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 89, Issue 10
*****************************************

Reply via email to