Fractional of DiffTime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|

Fractional of DiffTime

Baa
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Fractional of DiffTime

David McBride
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 <[hidden email]> 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
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: Fractional of DiffTime

Baa
Hello, David.

Interesting... There is also library num-hask, but no DiffTime there.

> 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.

It makes sense. OK. Thank you!


>
> 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 <[hidden email]> 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
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners 
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

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