New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Epsilon without Num #168
Comments
The
|
Clearly that makes sense, as you have to have some way to combine the different dimensions (though you could also use an infinity-norm, i.e. instance (Dim n, Epsilon a, Num a) => Epsilon (V n a) where
nearZero = nearZero . quadrance |
I suppose. But it's difficult to imagine a situation where you'd need birotate :: Angle -> Angle -> Point -> Point
birotate a1 a2
| nearZero da = id
| otherwise = mkRotation da
where
da = a1 + a2 How would |
Sorry, I apparently entered the function wrong. As I said, they're
I do this for types which have useful additive properties (and maybe even subtraction and negation) but for which multiplying them doesn't make sense; you can still do scalar multiplication with Of course, they have to be |
Ah, OK. Does that mean that |
That'll show me for summarizing a piece of code for a bug report! Here's the entire definition: newtype Angle a = Angle{ inRadians :: a }
deriving (Eq,Ord,Show,Functor)
instance Applicative Angle where
pure = Angle
(Angle f) <*> (Angle x) = Angle (f x)
instance Additive Angle where
zero = Angle 0
radians :: a -> Angle a
radians = Angle
inDegrees :: Floating a => Angle a -> a
inDegrees (Angle r) = r * (180 / pi)
degrees :: Floating a => a -> Angle a
degrees a = Angle (a * pi / 180) I can in this way refer consistently to angles without having to worry if I'm getting degrees or radians. I could of course just implement |
Thanks, that explanation helps. In that case, I think I'm on board with the idea of removing the |
There doesn't seem to be anything in
Epsilon
that would require instances to also be instances ofNum
. I have some numericnewtype
s that I'm makingAdditive
but not full instances ofNum
that I'd like to still beEpsilon
. Could theNum
constraint be removed?For instance, for dimensioned quantities:
The text was updated successfully, but these errors were encountered: