## Monadic space library? A vector of coordinates wrapped in a monad of unspecified type?

Question

This must exist, right? It seems to me that points in mathematical spaces are often made to carry extra baggage. In my case, I'd like to label each point in an n-dimensional space with a name and a domain-specific type. Is a monad the right way to represent such extra baggage, or is a parameterized record the best way to do it? And what libraries provide this sort of capability out of box?

Show source

## Answers to Monadic space library? A vector of coordinates wrapped in a monad of unspecified type? ( 1 )

1. Not sure if that's what you mean, but it might be this what I've defined in the `manifolds` library (at the moment it's more of an experimental implementation detail, not a stable exported type):

``````data WithAny x y = WithAny y !x
``````

`WithAny x y` behaves as a vector space (more generally, as a manifold) in the same way as `x` does, but each value also has an extra `y` associated with it which is considered simply as a “tag” and not changed through the continuous-space operations. E.g.

``````  WithAny y x ^+^ WithAny _ ξ = WithAny y \$ x ^+^ ξ
``````

“Orthogonally” to those instances, the type is a monad in the second argument, with

``````  fmap f (WithAny y x) = WithAny (f y) x
``````

(As danidiaz remarks, it's in particular also a comonad, I just haven't added that instance yet.)

Actually I'm a bit skeptical myself if the semantics of this type are really sensible. After all, points annotated with different discrete tags basically live in completely disjoint space(-sector)s, yet they can appear arbitrarily close through the vectorspace view, indeed you have `distance (Withany t x) (WithAny q x) ≡ 0` even if these points are clearly not the same.