bokesan / intervalmap Goto Github PK
View Code? Open in Web Editor NEWHaskell interval collections
License: BSD 3-Clause "New" or "Revised" License
Haskell interval collections
License: BSD 3-Clause "New" or "Revised" License
The interface here is close to the standard Data.Map but it lacks lookupLE (lookup less than or equal) and lookupGE (greater or equal). I am using intervals to cover time periods but there are times that no interval covers, so in that case I need to be able to find the closest match on either side. I realise I could use split for this but for what I want I would need to do something like
IMap.split i >>> IMap.findMax *** IMap.findMin $ imap
but it may be possible to do this more efficiently in the library. If it is not, this issue can be closed.
Any open or half-open interval with the same lower and upper bound should be considered empty (i.e. (x,x]
, [x,x)
and (x,x)
). The function IntervalMap.isEmpty
agrees with this interpretation, where IntervalMap.isEmpty (IntervalCO 1 1)
is True
. However, this is not consistent with the results of IntervalMap.intersecting
or IntervalMap.overlaps
, since an empty interval should never intersect or overlap with any other interval.
Current behavior: IntervalMap.overlaps (IntervalCO 1 1) (InvervalCO 0 2)
is True
Expected behavior: IntervalMap.overlaps (IntervalCO 1 1) (InvervalCO 0 2)
should be False
Current behavior :IntervalMap.intersecting (fromList [(IntervalCO 0 2, "0_2")]) (IntervalCO 1 1)
is [(IntervalCO 0 2, "0_2")]
Expected behavior: IntervalMap.intersecting (fromList [(IntervalCO 0 2, "0_2")]) (IntervalCO 1 1)
should be []
I'm sure it's a minor oversight: Is Data.IntervalMap.Strict's lookup
function really supposed to take a list of assocs
?
import qualified Data.IntervalMap.Strict as IM
fun :: IM.IntervalMap Int String
fun ivmap k v =
case IM.lookup k ivmap of
Just _x -> "Good"
Nothing -> "Bad"
GHC error:
Couldn't match expected type ‘[(Int, IM.IntervalMap Int String)]'
with actual type ‘IM.IntervalMap Int String’
Add semigroup instances.
See also: https://ghc.haskell.org/trac/ghc/wiki/Migration/8.4#SemigroupMonoidsuperclasses
Building library for IntervalMap-0.5.3.1..
[1 of 9] Compiling Data.IntervalMap.Interval ( Data/IntervalMap/Interval.hs, dist/build/Data/IntervalMap/Interval.o )
[2 of 9] Compiling Data.IntervalMap.Generic.Interval ( Data/IntervalMap/Generic/Interval.hs, dist/build/Data/IntervalMap/Generic/Interval.o )
[3 of 9] Compiling Data.IntervalMap.Generic.Base ( Data/IntervalMap/Generic/Base.hs, dist/build/Data/IntervalMap/Generic/Base.o )
Data/IntervalMap/Generic/Base.hs:254:10: error:
• Could not deduce (Semigroup (IntervalMap i v))
arising from the superclasses of an instance declaration
from the context: (Interval i k, Ord i)
bound by the instance declaration
at Data/IntervalMap/Generic/Base.hs:254:10-58
• In the instance declaration for ‘Monoid (IntervalMap i v)’
|
254 | instance (Interval i k, Ord i) => Monoid (IntervalMap i v) where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.