5 ms·
And note that there is no way to resolve this without some fundamental changes as Haskell requires that the two operands and the resultant type share a type. (O
by Guvante 12y ago
And note that there is no way to resolve this without some fundamental changes as Haskell requires that the two operands and the resultant type share a type. (Otherwise you could do some tricks with recursive types to accomplish this)
- wyager 12y ago>Haskell requires that the two operands and the resultant type share a type. Most physical unit libraries simply describe a "unit-ed" multiplication/division/etc operator, so you write code like let v = (5 ~* meter) / (1 *~ second) This division operator would replace the standard one. This requires using Haskell extensions that support dependent types, but the libraries certainly exist. I've used "Dimensional" before.
- Guvante 12y agoCertainly avoiding using naked `*` avoids the problem, I was talking specifically about that operator.
- JadeNB 12y agoI think that this is true only if you want to be an instance of `Num`, which makes sense: the collection of, say, lengths is not such an instance, because you cannot multiply two lengths and get a length. Nothing stops us from defining (simplified) data Unit a = Unit a [String] (*) (Unit a as) (Unit b bs) = Unit (a Main.* b) (as ++ bs) Of course, we will then have to disambiguate `` when we use it in the code. Another option would be to give it another name, like `unit` (or something less awful).
- Guvante 12y agoI didn't think there was a way to set `*` without losing `Num` (which is required for raw numbers in your code).