on master help sign in
Introduce class Negatable
bfa343cMarkus Pfeiffer
libs/prelude/Prelude/Classes.idr+16
@@ -137,6 +137,22 @@ instance (Ord a, Ord b) => Ord (a, b) where
137 then compare xl yl
137 then compare xl yl
138 else compare xr yr
138 else compare xr yr
139
139
140+
141+-- --------------------------------------------------------- [ Negatable Class ]
142+||| The Negatable class defines a typeclass for which negation works.
143+||| This is used for implementing unary -
144+class Negatable a where
145+ negate : a -> a
146+
147+instance Negatable Integer where
148+ negate x = (-1) * x
149+
150+instance Negatable Int where
151+ negate x = (-1) * x
152+
153+instance Negatable Float where
154+ negate x = (-1.) * x
155+
140-- --------------------------------------------------------- [ Numerical Class ]
156-- --------------------------------------------------------- [ Numerical Class ]
141||| The Num class defines basic numerical arithmetic.
157||| The Num class defines basic numerical arithmetic.
142class Num a where
158class Num a where