Last active
November 27, 2019 18:33
-
-
Save chrisdone/86a186c52959d2f22f8eaf73d07135de to your computer and use it in GitHub Desktop.
TExp Num?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Num a => Num (Q (TExp (SomeNamedWith IsNonzero a))) where | |
fromInteger 0 = error "It's zero, fool!" | |
fromInteger n = [|| someNamedWith IsNonzero (fromInteger n) ||] | |
fine :: Double | |
fine = | |
case $$(1) :: SomeNamedWith IsNonzero Double of | |
(SomeNamedWith p divisor) -> | |
divide p 123 divisor | |
--- or | |
newtype NonZero = NonZero Integer | |
deriving (Show) | |
instance Num (Q (TExp NonZero)) where | |
qa + qb = error "Nope." | |
qa * qb = error "Nope." | |
abs x = [|| let NonZero y = $$x in NonZero (abs y) ||] | |
signum x = [|| let NonZero y = $$x in NonZero (signum y) ||] | |
negate x = [|| let NonZero y = $$x in NonZero (negate y) ||] | |
fromInteger x = if x /= 0 then [|| NonZero x ||] else error "Zero!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment