Say I have a type Path a = Double -> a
. That describes some notion of a "path" in a given type a
. In my case I want to use this to draw a curve in a 2-dimensional space. I use diagrams
so let a = P2 Double
(P2
).
What I'm looking for is a (generic) way of sampling any path p :: Path (P2 Double)
so that I can generate a smooth curve. Currently I just generate a fixed set of Double
s that I sample p
along. However, this only works nicely if p
is relatively smooth w.r.t. the sample rate.
Can't be done. If you want a "good" sample of a function, you must assume something about smoothness of the function; without any assumptions functions can be wildly weird. For example, the Weierstrass function is continuous everywhere and differentiable nowhere; the rationality indicator is bounded but discontinuous everywhere; and indeed by any sane metric the vast majority of functions are not even computable let alone easily interrogatable for a set of "representative" inputs.
So make some assumptions, or demand that the user tell you how to sample.