The Haskell adventure continues.
At the moment, i am trying to construct my own Fraction type in Haskell that suits my needs. It's basically just a type Fraction{ n:: Int , d:: Int} and a lot of functions , most of them are of type x->Fraction
So what i wanna do now is making sure that fractions can only be positive, or negative in the numerator, positive in denominator, by converting any other possibilities to one of those.
--e.g
(Fraction (3 (-5))->Fraction (-3) 5
--and
(Fraction (-3) (-5))->Fraction 3 5
every time some function x->Fraction would return one of those. I assume there must be a smarter way to do this than modifying every x->Fraction function one by one. My guess would be already at the Fraction Type definition.
I haven't been programming for that long so i might not be completely up to beat on the technical terms.
Thanks for reading, and thanks if you answer
EDIT
I decided to go with the Eq Instance solution, and just added that if Signum numerator*Signum denominator doesn't match , return false, to the guard. I had to make that anyways to divide num. and den. with HCD before comparing
The smart-constructor that i originally asked for, is also gonna be used in my Matrix nXn (Q) Module that I'm making on the same time :)
Great answers. Thanks.