Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Last active November 27, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdone/86a186c52959d2f22f8eaf73d07135de to your computer and use it in GitHub Desktop.
Save chrisdone/86a186c52959d2f22f8eaf73d07135de to your computer and use it in GitHub Desktop.
TExp Num?
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