[GHC] #13652: Add integer division to GHC.TypeLits

GHC ghc-devs at haskell.org
Wed Oct 4 17:07:02 UTC 2017


#13652: Add integer division to GHC.TypeLits
-------------------------------------+-------------------------------------
        Reporter:  vagarenko         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Core Libraries    |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4002
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by RyanGlScott):

 * differential:  D4002 => Phab:D4002


Comment:

 Replying to [comment:3 vagarenko]:
 > like this:
 > {{{#!hs
 > type DivMod a b = (Div a b, Mod a b)
 > }}}
 > ?

 Yes.

 > Why would it be less performant than baked in `DivMod`? Because `a` and
 `b` would be reduced twice?

 Indeed. Internally, `div` and `mod` (on which the type-level `Div` and
 `Mod` are based) are defined in terms of `divMod`, so this definition of
 `DivMod` would likely compute `divMod` twice. I can't give you an accurate
 estimate of how many CPU cycles that would waste, but there is certainly
 some inefficiency there.

 But then again, this is your feature request, so I'll leave the final call
 up to you. Is the status quo (having just `Div` and `Mod`) acceptable for
 you? Or do you want to see `base` have the full trifecta of `Div`, `Mod`,
 and `DivMod`, each of which are based on their respective machine
 arithmetic operations?

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13652#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list