[GHC] #15622: Generalize `E{0,1,2,3,6,9,12}` from `Data.Fixed`
GHC
ghc-devs at haskell.org
Sun Sep 9 15:14:59 UTC 2018
#15622: Generalize `E{0,1,2,3,6,9,12}` from `Data.Fixed`
-------------------------------------+-------------------------------------
Reporter: rockbmb | Owner: (none)
Type: feature | Status: new
request |
Priority: normal | Milestone: 8.6.1
Component: Core | Version: 8.4.3
Libraries |
Keywords: base, | Operating System: Unknown/Multiple
Data.Fixed |
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Hello;
I'm creating this email to propose a change to `Data.Fixed`. Full credit
for this idea goes to Bhavik Mehta (@b-mehta on GitHub), who implemented
it in this [https://github.com/dmcclean/exact-pi/pull/8 PR] for `exact-
pi`.
In `Data.Fixed` there are several `E`-prefixed datatypes used to represent
a certain number of digits of precision in fixed-precision arithmetic. For
example, `E1` has 1 decimal place, `E12` has 12. Each of them,
`E{0,1,2,3,6,9,12}` is hardcoded. If more precision types are to be
provided, they have to be hardcoded as well, and all of these types
resemble each other. I think there is room for improvement here.
Instead of having
{{{#!hs
data E0
instance HasResolution E0 where
resolution _ = 1
}}}
and repeating it as many times as there are `E` datatypes, I propose to
add the following type:
{{{#!hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
import GHC.TypeLits (Nat, KnownNat, natVal)
data E (n :: Nat)
}}}
and then do
{{{#!hs
instance KnownNat n => HasResolution (E n) where
resolution _ = 10^natVal (undefined :: E n)
}}}
just once, replacing `data E0` with `type E0 = E 0` (and the same for the
rest of them) to continue reexporting these types. `E` should also be
exported.
I've sent an email to the Core Libraries Committee regarding this issue.
This is my first contribution to GHC, if I'm doing something incorrectly
please tell me.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15622>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list