[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] Num nstances for Data.Monoid.{First,Last}
From:       Oliver Charles <ollie () ocharles ! org ! uk>
Date:       2017-03-23 13:52:43
Message-ID: CAGRp5RmtL5kHU_CVsYceqWBzcwxNDxiQBJ7gw6Lqyq9y2Ld3SQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


We already have Num instances on things like Sum and Product, could we have
them on First and Last? I mostly want fromInteger on these types. To give
you a real world example:

    keySpeed :: L.Fold KeyboardEventData Double
    keySpeed =
      L.foldMap
        (\KeyboardEventData {keyboardEventKeyMotion} ->
           case keyboardEventKeyMotion of
             Pressed -> Last (Just 1)
             Released -> Last (Just 0))
        (fromMaybe 0 . getLast)

keySpeed folds (under Control.Foldl) events from a UI system into the
number 1 if the key has been pressed and 0 if the key has been released.
It's OK in the above form, but if Last had a Num instance, I could just have

             Pressed -> 1
             Released -> 0

Which I find preferable.

Any thoughts?
- Ollie

[Attachment #5 (text/html)]

<div dir="ltr">We already have Num instances on things like Sum and Product, could we \
have them on First and Last? I mostly want fromInteger on these types. To give you a \
real world example:<div><br></div><div><div><font face="monospace">      keySpeed :: \
L.Fold KeyboardEventData Double</font></div><div><font face="monospace">      \
keySpeed =</font></div><div><font face="monospace">         \
L.foldMap</font></div><div><font face="monospace">            (\KeyboardEventData \
{keyboardEventKeyMotion} -&gt;</font></div><div><font face="monospace">               \
case keyboardEventKeyMotion of</font></div><div><font face="monospace">               \
Pressed -&gt; Last (Just 1)</font></div><div><font face="monospace">                  \
Released -&gt; Last (Just 0))</font></div><div><font face="monospace">            \
(fromMaybe 0 . getLast)</font></div></div><div><br></div><div>keySpeed folds (under \
Control.Foldl) events from a UI system into the number 1 if the key has been pressed \
and 0 if the key has been released. It&#39;s OK in the above form, but if Last had a \
Num instance, I could just have</div><div><br></div><div><div><font face="monospace"> \
Pressed -&gt; 1</font></div><div><font face="monospace">                    Released \
-&gt; 0</font></div></div><div><font face="monospace"><br></font></div><div>Which I \
find preferable.</div><div><br></div><div>Any thoughts?</div><div>- Ollie</div></div>


[Attachment #6 (text/plain)]

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic