Remix.run Logo
amelius 5 days 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 5 days ago | parent [-]

The `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 4 days ago | parent [-]

Ok, but I'd also want to convert between polar and cartesian coordinates.