I am working on creating multiple instances for a fraction data type in Haskell, and I wonder if there is a place where I could implement the ^ operator.
I mean, I have several instances of various types of Num , and in these cases I define common operations, such as + , - , etc.
At the same time, the data type behaves like a normal number, since I want it (this means that I can call things like (Frac 1 2) + (Frac 1 4) and return Frac 3 4 )
What I'm trying to do is implement ^ directly. Right now, I have defined it as follows:
(|^|) :: Fraction -> Int -> Fraction (|^|) f = foldr (*) mempty . flip replicate f
When I try to change the function name to ^ , I get an error because it contradicts the definition of Prelude ^ . Is there a Num type that I can provide my Fraction type with an instance to allow me to use the ^ operator on it?
Thanks!
source share