rope 0.2 → 0.3
raw patch · 4 files changed
+292/−3 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Rope.Annotated: (:*:) :: f a -> g a -> :*: f g a
+ Data.Rope.Annotated: append :: (Annotation f) => Ann a f -> Ann b f -> Ann (a :<> b) f
+ Data.Rope.Annotated: break :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated: class Annotation f
+ Data.Rope.Annotated: cons :: (Annotation f, Reducer t Rope) => t -> Ann a f -> (forall c. Ann (Cons c t a) f -> r) -> r
+ Data.Rope.Annotated: data (:*:) f g a
+ Data.Rope.Annotated: data A s a
+ Data.Rope.Annotated: data Cons s t a
+ Data.Rope.Annotated: data Drop n a
+ Data.Rope.Annotated: data Empty
+ Data.Rope.Annotated: data Init a t
+ Data.Rope.Annotated: data Snoc a s t
+ Data.Rope.Annotated: data Tail t a
+ Data.Rope.Annotated: data Take n a
+ Data.Rope.Annotated: drop :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated: dropWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated: empty :: (Annotation f) => Ann Empty f
+ Data.Rope.Annotated: fstF :: (f :*: g) :~> f
+ Data.Rope.Annotated: head :: (Unpackable t) => A s a -> t
+ Data.Rope.Annotated: last :: (Unpackable t) => A s a -> t
+ Data.Rope.Annotated: null :: A s a -> Bool
+ Data.Rope.Annotated: sndF :: (f :*: g) :~> g
+ Data.Rope.Annotated: snoc :: (Annotation f, Reducer t Rope) => Ann a f -> t -> (forall c. Ann (Snoc c t a) f -> r) -> r
+ Data.Rope.Annotated: span :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated: splitAt :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated: take :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r
+ Data.Rope.Annotated: takeWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r
+ Data.Rope.Annotated: type Ann a f = A a (f a)
+ Data.Rope.Annotated: uncons :: (Annotation f, Unpackable t) => Ann a f -> Maybe (t, Ann (Tail t a) f)
+ Data.Rope.Annotated: unit :: (Reducer t Rope, Annotation f) => t -> Ann a f
+ Data.Rope.Annotated: unsnoc :: (Annotation f, Unpackable t) => Ann a f -> Maybe (Ann (Init a t) f, t)
+ Data.Rope.Annotated.Internal: (:*:) :: f a -> g a -> :*: f g a
+ Data.Rope.Annotated.Internal: A :: !Rope -> a -> A s a
+ Data.Rope.Annotated.Internal: append :: (Annotation f) => Ann a f -> Ann b f -> Ann (a :<> b) f
+ Data.Rope.Annotated.Internal: appendA :: (Annotation f) => Ann a f -> Ann b f -> f (a :<> b)
+ Data.Rope.Annotated.Internal: break :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: class Annotation f
+ Data.Rope.Annotated.Internal: cons :: (Annotation f, Reducer t Rope) => t -> Ann a f -> (forall c. Ann (Cons c t a) f -> r) -> r
+ Data.Rope.Annotated.Internal: consA :: (Annotation f) => Int -> Rope -> f a -> f b
+ Data.Rope.Annotated.Internal: data (:*:) f g a
+ Data.Rope.Annotated.Internal: data A s a
+ Data.Rope.Annotated.Internal: data Cons s t a
+ Data.Rope.Annotated.Internal: data Drop n a
+ Data.Rope.Annotated.Internal: data Empty
+ Data.Rope.Annotated.Internal: data Init a t
+ Data.Rope.Annotated.Internal: data Snoc a s t
+ Data.Rope.Annotated.Internal: data Tail t a
+ Data.Rope.Annotated.Internal: data Take n a
+ Data.Rope.Annotated.Internal: drop :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: dropA :: (Annotation f) => Int -> Rope -> f a -> f b
+ Data.Rope.Annotated.Internal: dropWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: empty :: (Annotation f) => Ann Empty f
+ Data.Rope.Annotated.Internal: emptyA :: (Annotation f) => f Empty
+ Data.Rope.Annotated.Internal: fstF :: (f :*: g) :~> f
+ Data.Rope.Annotated.Internal: head :: (Unpackable t) => A s a -> t
+ Data.Rope.Annotated.Internal: instance [incoherent] (Annotation f, Annotation g) => Annotation (f :*: g)
+ Data.Rope.Annotated.Internal: instance [incoherent] (Applicative f, Applicative g) => Applicative (f :*: g)
+ Data.Rope.Annotated.Internal: instance [incoherent] (Foldable f, Foldable g) => Foldable (f :*: g)
+ Data.Rope.Annotated.Internal: instance [incoherent] (Functor f, Functor g) => Functor (f :*: g)
+ Data.Rope.Annotated.Internal: instance [incoherent] (Traversable f, Traversable g) => Traversable (f :*: g)
+ Data.Rope.Annotated.Internal: instance [incoherent] Comonad (A s)
+ Data.Rope.Annotated.Internal: instance [incoherent] Foldable (A s)
+ Data.Rope.Annotated.Internal: instance [incoherent] Functor (A s)
+ Data.Rope.Annotated.Internal: instance [incoherent] Measured Offset (A s a)
+ Data.Rope.Annotated.Internal: instance [incoherent] Traversable (A s)
+ Data.Rope.Annotated.Internal: last :: (Unpackable t) => A s a -> t
+ Data.Rope.Annotated.Internal: null :: A s a -> Bool
+ Data.Rope.Annotated.Internal: sndF :: (f :*: g) :~> g
+ Data.Rope.Annotated.Internal: snoc :: (Annotation f, Reducer t Rope) => Ann a f -> t -> (forall c. Ann (Snoc c t a) f -> r) -> r
+ Data.Rope.Annotated.Internal: snocA :: (Annotation f) => Rope -> Int -> f a -> f b
+ Data.Rope.Annotated.Internal: span :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: splitAt :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: splitAtA :: (Annotation f) => Int -> Rope -> f a -> (f b, f c)
+ Data.Rope.Annotated.Internal: take :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: takeA :: (Annotation f) => Int -> Rope -> f a -> f b
+ Data.Rope.Annotated.Internal: takeWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r
+ Data.Rope.Annotated.Internal: type :~> f g = forall a. f a -> g a
+ Data.Rope.Annotated.Internal: type Ann a f = A a (f a)
+ Data.Rope.Annotated.Internal: uncons :: (Annotation f, Unpackable t) => Ann a f -> Maybe (t, Ann (Tail t a) f)
+ Data.Rope.Annotated.Internal: unit :: (Reducer t Rope, Annotation f) => t -> Ann a f
+ Data.Rope.Annotated.Internal: unitA :: (Annotation f) => Rope -> f a
+ Data.Rope.Annotated.Internal: unpack :: (Unpackable t) => A s a -> [t]
+ Data.Rope.Annotated.Internal: unsnoc :: (Annotation f, Unpackable t) => Ann a f -> Maybe (Ann (Init a t) f, t)
+ Data.Rope.Util.Comonad: class (Functor w) => Comonad w
+ Data.Rope.Util.Comonad: duplicate :: (Comonad w) => w a -> w (w a)
+ Data.Rope.Util.Comonad: extend :: (Comonad w) => (w a -> b) -> w a -> w b
+ Data.Rope.Util.Comonad: extract :: (Comonad w) => w a -> a
Files
- Data/Rope/Annotated.hs +38/−0
- Data/Rope/Annotated/Internal.hs +237/−0
- Data/Rope/Util/Comonad.hs +11/−0
- rope.cabal +6/−3
+ Data/Rope/Annotated.hs view
@@ -0,0 +1,38 @@+module Data.Rope.Annotated+ ( + -- * Annotated 'Rope's + A(rope) + , Ann+ , Annotation+ -- * Unpacking Annotated 'Rope'+ , null -- :: A s a -> Bool+ , head -- :: Unpackable t => A s a -> t+ , last -- :: Unpackable t => A s a -> t+ , uncons -- :: (Annotation f, Unpackable t, Uncons t a b) => Ann a f -> Maybe (t, Ann b f)+ , unsnoc -- :: (Annotation f, Unpackable t, Unsnoc t a b) => Ann a f -> Maybe (t, Ann b f)++ -- * Building Annotated 'Rope'+ , empty -- :: (Annotation f) => Ann Empty f + , append -- :: (Annotation f, Append a b c) => Ann a f -> Ann b f -> Ann c f+ , unit -- :: (Annotation f, Reducer t Rope) => t -> Ann a f+ , snoc -- :: (Annotation f, Reducer t Rope) => t -> Ann a f -> (forall c. Ann (Snoc c t a) f -> r) -> r+ , cons -- :: (Annotation f, Reducer t Rope) => Ann a f -> t -> (forall c. Ann (Cons c t a) f -> r) -> r++ -- * Cutting An Annotated 'Rope'+ , splitAt -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+ , drop -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r+ , take -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+ , break -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+ , span -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+ , takeWhile -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+ , dropWhile -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r++ -- * Type-level constructors+ , Drop, Take, Snoc, Cons, Tail, Init, Empty, (:<>)++ -- * Annotation Product+ , (:*:)(..), fstF, sndF+ ) where++import Prelude hiding (null, head, last, take, drop, span, break, splitAt, takeWhile, dropWhile)+import Data.Rope.Annotated.Internal
+ Data/Rope/Annotated/Internal.hs view
@@ -0,0 +1,237 @@+{-# LANGUAGE TypeOperators, Rank2Types, EmptyDataDecls, + MultiParamTypeClasses, FunctionalDependencies, + FlexibleContexts, FlexibleInstances, UndecidableInstances,+ IncoherentInstances, OverlappingInstances #-}+module Data.Rope.Annotated.Internal + ( A(A,rope)+ , Ann+ , Annotation(..)+ , (:~>)++ , null -- :: A s a -> Bool+ -- * Unpackable Ropes+ , head -- :: Unpackable t => A s a -> t+ , last -- :: Unpackable t => A s a -> t+ , unpack -- :: Unpackable t => A s a -> [t]+ , uncons -- :: (Annotation f, Unpackable t) => Ann a f -> Maybe (t, Ann (Tail t a) f)+ , unsnoc -- :: (Annotation f, Unpackable t) => Ann a f -> Maybe (t, Ann (Init a t) f)++ -- * Splitting Ropes+ , drop -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r+ , take -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+ , splitAt -- :: (Annotation f) => Int -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r++ -- * Building Ropes+ , unit -- :: (Annotation f, Reducer t Rope) => t -> Ann a f+ , snoc -- :: (Annotation f, Reducer t Rope) => t -> Ann a f -> (forall c. Ann (Snoc c t a) f -> r) -> r+ , cons -- :: (Annotation f, Reducer t Rope) => Ann a f -> t -> (forall c. Ann (Cons c t a) f -> r) -> r+ , empty -- :: (Annotation f) => Ann Empty f + , append -- :: (Annotation f, ) => Ann a f -> Ann b f -> Ann (a :<> b) f++ -- * Breaking Ropes++ , break -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+ , span -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+ , takeWhile -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+ , dropWhile -- :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r++ -- * Type-level constructors+ , Drop, Take, Snoc, Cons, Tail, Init, Empty, (:<>)++ -- * Annotation Products+ , (:*:)(..), fstF, sndF+ ) where++import Prelude hiding (null, head, last, take, drop, span, break, splitAt, takeWhile, dropWhile)+import Control.Applicative hiding (empty)+import Data.Rope.Util.Comonad+import Data.Monoid+import qualified Data.Rope.Util.Reducer as Reducer+import Data.Rope.Util.Reducer (Reducer)+import Data.FingerTree (Measured(..))+import Data.Foldable (Foldable, foldMap)+import qualified Data.Foldable+import Data.Traversable (Traversable(traverse))+import qualified Data.Rope.Internal as Rope+import Data.Rope.Body (Offset(..))+import Data.Rope.Internal (Rope(..),Breakable, Unpackable)++type f :~> g = forall a. f a -> g a++data A s a = A { rope :: !Rope, extractA :: a }++null :: A s a -> Bool+null = Rope.null . rope++head :: Unpackable t => A s a -> t+head = Rope.head . rope++last :: Unpackable t => A s a -> t+last = Rope.last . rope++type Ann a f = A a (f a)++instance Measured Offset (A s a) where+ measure = measure . rope++instance Functor (A s) where+ fmap f (A s a) = A s (f a) ++instance Comonad (A s) where+ extract = extractA+ extend f a@(A s _) = A s (f a)+ duplicate a@(A s _) = A s a++instance Foldable (A s) where+ foldr f z (A _ a) = f a z+ foldr1 _ (A _ a) = a+ foldl f z (A _ a) = f z a+ foldl1 _ (A _ a) = a+ foldMap f (A _ a) = f a++instance Traversable (A s) where+ traverse f (A s a) = A s <$> f a++class Annotation f where+ unitA :: Rope -> f a+ splitAtA :: Int -> Rope -> f a -> (f b, f c)+ takeA :: Int -> Rope -> f a -> f b+ dropA :: Int -> Rope -> f a -> f b+ snocA :: Rope -> Int -> f a -> f b+ consA :: Int -> Rope -> f a -> f b+ emptyA :: f Empty+ appendA :: Ann a f -> Ann b f -> f (a :<> b)++ takeA n r = fst . splitAtA n r+ dropA n r = snd . splitAtA n r++empty :: Annotation f => Ann Empty f+empty = A Rope.empty emptyA+++unit :: (Reducer t Rope, Annotation f) => t -> Ann a f+unit t = A r (unitA r)+ where + r :: Rope+ r = Reducer.unit t++splitAt :: Annotation f => Int -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+splitAt n (A r a) k = k (A r b) (A r c) + where (b, c) = splitAtA n r a++drop :: Annotation f => Int -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r+drop n (A r a) k = k (A r (dropA n r a))++take :: Annotation f => Int -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+take n (A r a) k = k (A r (takeA n r a))++snoc :: (Annotation f, Reducer t Rope) => Ann a f -> t -> (forall c. Ann (Snoc c t a) f -> r) -> r+snoc (A r a) t k = k (A r' (snocA r' (Rope.length r' - Rope.length r) a))+ where r' = Reducer.snoc r t ++cons :: (Annotation f, Reducer t Rope) => t -> Ann a f -> (forall c. Ann (Cons c t a) f -> r) -> r+cons t (A r a) k = k (A r' (consA (Rope.length r' - Rope.length r) r' a))+ where r' = Reducer.cons t r++append :: Annotation f => Ann a f -> Ann b f -> Ann (a :<> b) f+append a@(A r _) b@(A s _) = A (r `mappend` s) (a `appendA` b)++break :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+break p (A r a) k = k (A x b) (A y c) where+ (x,y) = Rope.break p r+ (b,c) = splitAtA (Rope.length x) r a++span :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> Ann (Drop n a) f -> r) -> r+span p (A r a) k = k (A x b) (A y c) where+ (x,y) = Rope.span p r+ (b,c) = splitAtA (Rope.length x) r a++takeWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Take n a) f -> r) -> r+takeWhile p (A r a) k = k (A x b) where+ x = Rope.takeWhile p r+ b = takeA (Rope.length x) r a++dropWhile :: (Annotation f, Breakable t) => (t -> Bool) -> Ann a f -> (forall n. Ann (Drop n a) f -> r) -> r+dropWhile p (A r a) k = k (A y c) where+ y = Rope.dropWhile p r+ c = dropA (Rope.length r - Rope.length y) r a++uncons :: (Annotation f, Unpackable t) => Ann a f -> Maybe (t, Ann (Tail t a) f)+uncons (A r a) = case Rope.uncons r of+ Just (c,cs) -> Just (c, A cs (dropA (Rope.length r - Rope.length cs) r a))+ Nothing -> Nothing++unsnoc :: (Annotation f, Unpackable t) => Ann a f -> Maybe (Ann (Init a t) f, t)+unsnoc (A r a) = case Rope.unsnoc r of+ Just (cs,c) -> Just (A cs (dropA (Rope.length cs) r a), c)+ Nothing -> Nothing++-- annotation product++infixr 5 :*:++data (f :*: g) a = f a :*: g a++fstF :: (f :*: g) :~> f+fstF ~(f :*: _) = f++sndF :: (f :*: g) :~> g+sndF ~(_ :*: g) = g++instance (Functor f, Functor g) => Functor (f :*: g) where+ fmap f (a :*: b) = fmap f a :*: fmap f b++instance (Applicative f, Applicative g) => Applicative (f :*: g) where+ pure a = pure a :*: pure a+ (f :*: g) <*> (a :*: b) = (f <*> a) :*: (g <*> b)++instance (Foldable f, Foldable g) => Foldable (f :*: g) where+ foldMap f (a :*: b) = foldMap f a `mappend` foldMap f b+ +instance (Traversable f, Traversable g) => Traversable (f :*: g) where+ traverse f (a :*: b) = (:*:) <$> traverse f a <*> traverse f b++instance (Annotation f, Annotation g) => Annotation (f :*: g) where+ unitA r = unitA r :*: unitA r+ emptyA = emptyA :*: emptyA+ dropA n r (f :*: g) = dropA n r f :*: dropA n r g+ takeA n r (f :*: g) = takeA n r f :*: takeA n r g+ splitAtA n r (f :*: g) = (f' :*: g' , f'' :*: g'') where+ (f',f'') = splitAtA n r f+ (g',g'') = splitAtA n r g+ snocA r n (f :*: g) = snocA r n f :*: snocA r n g+ consA n r (f :*: g) = consA n r f :*: consA n r g+ appendA (A r (a :*: a')) (A s (b :*: b')) = + appendA (A r a) (A s b) :*: appendA (A r a') (A s b')++ +data Take n a+data Drop n a+data Empty+data Cons s t a+data Snoc a s t+data (:<>) a b+data Tail t a+data Init a t++{-+class Append a b c | a b -> c+instance Append Empty a a+instance Append b c d => Append (a :<> b) c (a :<> d)+instance Append a b c => Append (Cons s t a) b (Cons s t c)+instance Append (Take n a) (Drop n a) a+instance Append a Empty a +instance Append a b (a :<> b)++class Uncons t a b | t a -> b+instance Uncons t (Cons s t a) a+instance Uncons t a (Tail t a)++class Unsnoc a t b | a t -> b+instance Unsnoc (Snoc a s t) t a+instance Unsnoc a t (Init a t)+-}++unpack :: Unpackable t => A s a -> [t]+unpack (A s _) = Rope.unpack s+
+ Data/Rope/Util/Comonad.hs view
@@ -0,0 +1,11 @@+module Data.Rope.Util.Comonad + ( Comonad(..)+ ) where++class Functor w => Comonad w where+ extract :: w a -> a+ duplicate :: w a -> w (w a)+ extend :: (w a -> b) -> w a -> w b++ duplicate = extend id+ extend f = fmap f . duplicate
rope.cabal view
@@ -1,5 +1,5 @@ name: rope-version: 0.2+version: 0.3 license: BSD3 license-file: LICENSE author: Edward A. Kmett@@ -7,8 +7,8 @@ stability: experimental homepage: http://comonad.com/reader category: Language-synopsis: Tools for manipulating fingertrees of bytestrings-description: Tools for manipulating fingertrees of bytestrings+synopsis: Tools for manipulating fingertrees of bytestrings with optional annotations+description: Tools for manipulating fingertrees of bytestrings with optional annotations copyright: (c) 2010 Edward A. Kmett build-type: Simple cabal-version: >=1.2@@ -22,8 +22,11 @@ utf8-string >= 0.3.5 && < 0.4 exposed-modules: Data.Rope+ Data.Rope.Annotated+ Data.Rope.Annotated.Internal Data.Rope.Body Data.Rope.Internal+ Data.Rope.Util.Comonad Data.Rope.Util.Reducer ghc-options: -Wall