I'm new to haskell, and from time to time I bump into a problem I'll try to describe here in a few words. Imagine, I want to declare different types for different measures so Haskell type system would find errors in my formulas:
newtype Dist = Km Float
newtype Time = H Float
newtype Velocity = KmH Float
(/) :: Dist → Time → Velocity
(Km d) / (H t) = KmH (d / v)
(*) :: Velocity → Time → Dist
(KmH v) * (H t) = Km (v * t)
so, any time when I try to use wrong units of measures in my formulas the compiler would bite.
The problem is that I can't implement ad-hoc polimorphism like this. With this code I bring ambiguity - the complier can distinguish my operator * and the one defined in Prelude. Declaration of an instance of Num class also is not possible since I need different types in parameters.
I'm wondering how people solve the problem usually.
Thanks in advance!