Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created November 26, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lysxia/ebe3bef85e11bd13928c94beb56aa7ab to your computer and use it in GitHub Desktop.
Save Lysxia/ebe3bef85e11bd13928c94beb56aa7ab to your computer and use it in GitHub Desktop.
What is this called?
-- | Ordered affine spaces are made of points and vectors.
--
-- - Vectors can be added, that's the 'Semigroup' superclass.
-- - Points can be translated along vectors using @('.+')@.
-- - Given two ordered points @i <= j@, @j '.-.?' i@ finds a vector @n@
-- such that @i + n = j@.
--
-- In other words, we only require the existence of "positive" vectors.
--
-- __Laws:__
--
-- @
-- (x '.+' v) '.+' w = x '.+' (v '<>' w)
-- x '<=' y ==> x '.+' (y '.-.' x) = y
-- (x '.+' v) '.-.' x = x
-- @
class (Ord (Point v), Semigroup v) => Affine v where
type Point v
infixr 6 .+
-- | Translation.
(.+) :: Point v -> v -> Point v
-- | Vector between two points.
-- @j .-.? i@ must be defined ('Just') if @i <= j@,
(.-.?) :: Point v -> Point v -> Maybe v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment