3 ms·
Can it also do reference frames? Like if I have a cartesian coordinates in one reference frame, can I use them in a type-safe way? E.g. not add two vectors in
by amelius 2y ago
Can it also do reference frames?
Like if I have a cartesian coordinates in one reference frame, can I use them in a type-safe way? E.g. not add two vectors in two reference frames? Same for polar coordinates?
Etc.
- cosmic_quanta 2y agoThe `dimensional` library doesn't provide this, no. However, it's easy to 'tag' data in Haskell using phantom types. For example, for vectors in reference frames: newtype Framed f a = MkFramed (Vector a) add :: Framed f a -> Framed f a -> Framed f a add (MkFramed vec1) (MkFramed vec2) = ... add vec1 and vec2 data ReferenceFrame1 data ReferenceFrame2 v1 :: Framed ReferenceFrame1 Double v1 = ... v2 :: Framed ReferenceFrame2 Double v2 = ... main :: IO () main = print $ v1 `add` v2 -- will not type check There might already be a library to do this
- amelius 2y agoOk, but I'd also want to convert between polar and cartesian coordinates.