Closed m-bock closed 4 years ago
Good idea. The range function confused me as well when i first saw it
Why should rangeNew d2 d2
error? Why not just remove the Pos diff
constraint and allow it to create empty vecs?
Also, i believe it's more common to format type signatures with operators first on the line, like this:
rangeNew
:: forall n1 n2 n3 max min diff
. Nat n1
=> Nat n2
=> Max n1 n2 max
=> Min n1 n2 min
=> Sub max min diff
=> Succ diff n3
=> n1 -> n2 -> Vec n3 Int
Yes true, we can omit the Pos
. That's better. It will not create empty vecs, but singleton ones.
rangeNew d2 d2 -- 2 +> empty
Regarding the formatting. I use purty
. It's not perfect but pretty good. https://github.com/bodil/purescript-sized-vectors/issues/25
right, i misthought
Wow this is a really good idea, good work!
Vec.range
vsUnfoldable.range
It's obvious that we cannot have an
Unfoldable
instance. However, I found it confusing once thatVec.range
andVec.range'
behave differently fromUnfoldable.range
and e.g.Array.range
.The common
range
functions include both endpoints and they don't have to be in the 'min, max' order. e.g.range 2 (-1)
is[2, 1, 0, -1]
In this library
range
only counts up and the second argument (either given inrange
or implicitly given inrange'
) is not the second endpoint but the size. If you misinterpret it as an endpoint (which happend to me and lead to an evil bug :) ) you'll wonder why it's not included.Couldn't we express the existing range just with
fill
(as its implementation) and thus maybe drop it?A different
range
and here's a suggestion of how a
range
could be closer to the 'real' one:This follows the same laws as the known
range
, it only adds a typelevel restriction: No negative endpoints, and they cannot be equal.