[GHC] #8697: Type rationals
GHC
ghc-devs at haskell.org
Sat Jan 25 01:40:02 UTC 2014
#8697: Type rationals
------------------------------------+-------------------------------------
Reporter: MikeIzbicki | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: None/Unknown
Difficulty: Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: |
------------------------------------+-------------------------------------
I've used GHC's Type Nats to implement my own type level rationals (code
below). This works fine, but the syntax is a little funky because you
have to write out the number as a fraction. For example, you must write
13/10 instead of 1.3; or even worse, 13/1 instead of 13. It would be nice
to just write the decimal notation.
I only see one potential problem with this feature: the dot in the decimal
notation could interfere with the dot in forall statements. I guess this
can be parsed unambiguously, but maybe not.
{{{
data Frac = Frac Nat Nat
data instance Sing (n::Frac) = SFrac Integer Integer
instance (SingI a, SingI b) => SingI ('Frac a b) where
sing = SFrac (fromSing (sing :: Sing a)) (fromSing (sing :: Sing b))
instance Fractional r => SingE (Kind :: Frac) r where
fromSing (SFrac a b) = fromIntegral a/fromIntegral b
type (/) a b = 'Frac a b
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8697>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list