[Haskell-beginners] Fractional of DiffTime

David McBride toad3k at gmail.com
Fri Aug 18 12:34:29 UTC 2017

DiffTimes need to be added and subtracted.  Unfortunately to add or
subtract anything you must implement the Num class.  By doing that you
now you either also support division and multiplication, or you throw
a runtime error.  This also comes up with vectors and matrices which
don't follow the usual Num rules, and so must have their own operators
in libraries to support their operations.

It has been suggested in the past to separate all of the operations in
the Num class into their constituent parts, say Addable, Subtractable,
Multiplicative, Negatable, etc, but you can imagine the boilerplate of
implementing all those classes for your own types, and also the hairy
types that would be inferred by the compiler for very simple
arithmetic functions.  But if you are going to go that far, you might
as well try to go all the way down into number theory.

So there are alternative numeric preludes that attempt to deal with
most of this stuff on hackage.  For example numeric-prelude, although
that library does not include DiffTime specifically, it likely has the
classes necessary to make a reasonable go at it.

On Fri, Aug 18, 2017 at 5:35 AM, Baa <aquagnu at gmail.com> wrote:
> Hello, List!
> DiffTime type has "closed" on itself operation "/". So,
>   (/) :: DiffTime -> DiffTime -> DiffTime
> But from a physics point of view, it doesn't make sense. When you
> divide hours by hours you get "dimensionless" value, not units
> (hours) but simple number (I'm not sure how it's named in English).
> And it's true for any physical values:
>    [m/s]  :  [m/s]  =  [Int]    (not [m/s] sure)
> Is it right to define CLOSED "/" for such set like DiffTime?
> ===
> Best regards, Paul
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

More information about the Beginners mailing list