it turns out annularwedge
function of diagrams package cannot take radius of 0 inner radius. must use wedge
instead.
to me, inner radius of 0 degenerate case of annularwedge
, should behave wedge
, tried combine them:
mywedge r2 r1 d | r1 == 0 = wedge r2 d | otherwise = annularwedge r2 r1 d
of course, doesn't work, , cannot figure out error means:
non type-variable argument in constraint: realfloat (n t) (use flexiblecontexts permit this) when checking ‘mywedge’ has inferred type mywedge :: forall t. (realfloat (n t), traillike t, v t ~ v2) => n t -> n t -> direction v2 (n t) -> angle (n t) -> t
in fact, turns out annularwedge
, wedge
have different constraints, surprised me:
annularwedge :: (traillike t, v t ~ v2, n t ~ n, realfloat n) => n -> n -> direction v2 n -> angle n -> t wedge :: (inspace v2 n t, orderedfield n, traillike t) => n -> direction v2 n -> angle n -> t
so how combine these 2 functions sane 1 accepts inner radius of 0 , right thing?
the solution simple. erikr said, add {-# language flexiblecontexts, typefamilies #-}
top of file. clear, these both safe extensions add (some extensions, overlapping instances or undecidable instances should make pause before enable them, these extensions mostly safe)
although isn't obvious, wedge
signature's constraints strictly weaker annularwedge
s ones.
if curious why signatures different, read on...
for starters, constraints, once track them down, aren't different. let's start wedge
.
(inspace v2 n t, orderedfield n, traillike t)
looking @ definition of inspace
, see has no functions, it's synonym: (v ~ v, n ~ n, additive v, num n) => inspace v n a
. then, can expand inspace v2 n t
(v t ~ v2, n t ~ n, additive v2, num n)
. similarly, orderedfield
turns out shorthand (floating n, ord n)
. now, constraint wedge
looks like
(traillike t, v t ~ v2, n t ~ n, additive v2, num n, floating n, ord n)
however, turns out can drop additive v2
constraint, since instance defined where additive
defined in linear.vector
, num n
redundant, given num n => fractional n => floating n
. leaves simpler constraint wedge
(traillike t, v t ~ v2, n t ~ n, floating n, ord n)
which looks whole lot constraint annularwedge
. in fact, difference wedge
constrains (floating n, ord n)
compared annularwedge
constraining realfloat n
. @ point, constraints similar enough make worth looking @ code wedge
. turns out wedge
makes use of _theta
, defined in hastheta
, corresponding v2
instance uses arctangent function (which, after chasing through couple more dependencies).
Comments
Post a Comment