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

#13652: Add integer division to GHC.TypeLits -------------------------------------+------------------------------------- Reporter: vagarenko | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHC.TypeLits currently lacks integer division type families and I can't see why. What is the reason for not having these methods of the `Integral` class at type level: {{{#!hs quot rem div mod quotRem divMod }}} ? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * component: Compiler => Core Libraries Comment: Libraries mailing list discussion: https://mail.haskell.org/pipermail/libraries/2017-June/028057.html -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Commit fa8035e3ee83aff5a20fc5e7e2697bac1686d6a6 added type-level versions of `Div` and `Mod` to `GHC.TypeNats`. The only remaining question—which I will ask to vagarenko—is it important to you to have a `DivMod` type family in `base` that uses the value-level `divMod` under the hood? I ask since one //could// define `DivMod` in terms of `Div` and `Mod`, but perhaps you're wanting something more performant than that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vagarenko): Replying to [comment:2 RyanGlScott]:
one could define DivMod in terms of Div and Mod
like this: {{{#!hs type DivMod a b = (Div a b, Mod a b) }}} ? Why would it be less performant than baked in `DivMod`? Because `a` and `b` would be reduced twice? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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): D4002 Wiki Page: | -------------------------------------+------------------------------------- Changes (by vagarenko): * differential: => D4002 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#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: | -------------------------------------+------------------------------------- Comment (by vagarenko): Okay, since we don't have `Fst` and `Snd` families in `base` anyway let's skip `DivMod`. Thanks for implementing this! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13652: Add integer division to GHC.TypeLits -------------------------------------+------------------------------------- Reporter: vagarenko | Owner: (none) Type: feature request | Status: closed Priority: normal | Milestone: Component: Core Libraries | Version: 8.0.1 Resolution: fixed | 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 vagarenko): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13652#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC