How to implement ^ operator in Haskell?

Viewed 534

I'm working on creating a bunch of instances for a Fraction data type in Haskell, and I'm wondering if there's a place I would be able to implement the ^ operator.

What I mean is, I've got several instances of various Num types, and within those instances, I define common operations such as +, -, etc.

With that, the data type behaves as a normal number, as I want it to (meaning I can call things like (Frac 1 2) + (Frac 1 4) and get back Frac 3 4)

What I'm trying to do is implement ^ directly. Right now, I've got it defined like this:

(|^|) :: Fraction -> Int -> Fraction
(|^|) f = foldr (*) mempty . flip replicate f  

When I try to change the name of the function to ^, I get an error because it conflicts with Prelude's definition of ^. Is there a Num type I can give my Fraction type an instance of to allow me to use the ^ operator on it?

Thanks!

1 Answers
Related