Num nstances for Data.Monoid.{First,Last}

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Num nstances for Data.Monoid.{First,Last}

Oliver Charles-3
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 =
        (\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

Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
Only members subscribed via the mailman list are allowed to post.