Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed keys dependency

  • Loading branch information...
commit 70f60eee9e0fec742328c756f81d426a40eea041 1 parent 1ae828c
@ekmett authored
View
3  src/Text/Trifecta/Highlight.hs
@@ -24,7 +24,6 @@ module Text.Trifecta.Highlight
import Control.Lens
import Data.Foldable as F
import Data.Int (Int64)
-import Data.Key hiding ((!))
import Data.List (sort)
import Data.Semigroup
import Data.Semigroup.Union
@@ -97,7 +96,7 @@ instance ToMarkup HighlightedRope where
, i <- [ (Leaf "span" "<span" ">" ! class_ (toValue $ show tok)) :@ bytes lo
, preEscapedString "</span>" :@ bytes hi
]
- ] ++ mapWithKey (\k i -> ln k :@ i) (L.elemIndices '\n' lbs)
+ ] ++ imap (\k i -> ln k :@ i) (L.elemIndices '\n' lbs)
go _ cs [] = unsafeLazyByteString cs
go b cs ((eff :@ eb) : es)
| eb <= b = eff >> go b cs es
View
33 src/Text/Trifecta/Util/IntervalMap.hs
@@ -48,14 +48,13 @@ module Text.Trifecta.Util.IntervalMap
) where
import Control.Applicative hiding (empty)
+import Control.Lens hiding ((<|),(|>))
import qualified Data.FingerTree as FT
import Data.FingerTree (FingerTree, Measured(..), ViewL(..), (<|), (><))
-import Data.Traversable (Traversable(traverse))
import Data.Foldable (Foldable(foldMap))
import Data.Semigroup
import Data.Semigroup.Reducer
import Data.Semigroup.Union
-import Data.Key
----------------------------------
-- 4.8 Application: interval trees
@@ -95,25 +94,23 @@ instance Traversable Interval where
data Node v a = Node (Interval v) a
-type instance Key (Node v) = Interval v
-
instance Functor (Node v) where
fmap f (Node i x) = Node i (f x)
-instance Keyed (Node v) where
- mapWithKey f (Node i x) = Node i (f i x)
+instance FunctorWithIndex (Interval v) (Node v) where
+ imap f (Node i x) = Node i (f i x)
instance Foldable (Node v) where
foldMap f (Node _ x) = f x
-instance FoldableWithKey (Node v) where
- foldMapWithKey f (Node k v) = f k v
+instance FoldableWithIndex (Interval v) (Node v) where
+ ifoldMap f (Node k v) = f k v
instance Traversable (Node v) where
traverse f (Node i x) = Node i <$> f x
-instance TraversableWithKey (Node v) where
- traverseWithKey f (Node i x) = Node i <$> f i x
+instance TraversableWithIndex (Interval v) (Node v) where
+ itraverse f (Node i x) = Node i <$> f i x
-- rightmost interval (including largest lower bound) and largest upper bound.
data IntInterval v = NoInterval | IntInterval (Interval v) v
@@ -134,27 +131,25 @@ instance Ord v => Measured (IntInterval v) (Node v a) where
newtype IntervalMap v a = IntervalMap { runIntervalMap :: FingerTree (IntInterval v) (Node v a) }
-- ordered lexicographically by interval
-type instance Key (IntervalMap v) = Interval v
-
instance Functor (IntervalMap v) where
fmap f (IntervalMap t) = IntervalMap (FT.unsafeFmap (fmap f) t)
-instance Keyed (IntervalMap v) where
- mapWithKey f (IntervalMap t) = IntervalMap (FT.unsafeFmap (mapWithKey f) t)
+instance FunctorWithIndex (Interval v) (IntervalMap v) where
+ imap f (IntervalMap t) = IntervalMap (FT.unsafeFmap (imap f) t)
instance Foldable (IntervalMap v) where
foldMap f (IntervalMap t) = foldMap (foldMap f) t
-instance FoldableWithKey (IntervalMap v) where
- foldMapWithKey f (IntervalMap t) = foldMap (foldMapWithKey f) t
+instance FoldableWithIndex (Interval v) (IntervalMap v) where
+ ifoldMap f (IntervalMap t) = foldMap (ifoldMap f) t
instance Traversable (IntervalMap v) where
traverse f (IntervalMap t) =
IntervalMap <$> FT.unsafeTraverse (traverse f) t
-instance TraversableWithKey (IntervalMap v) where
- traverseWithKey f (IntervalMap t) =
- IntervalMap <$> FT.unsafeTraverse (traverseWithKey f) t
+instance TraversableWithIndex (Interval v) (IntervalMap v) where
+ itraverse f (IntervalMap t) =
+ IntervalMap <$> FT.unsafeTraverse (itraverse f) t
instance Ord v => Measured (IntInterval v) (IntervalMap v a) where
measure (IntervalMap m) = measure m
View
17 src/Text/Trifecta/Util/It.hs
@@ -32,7 +32,6 @@ import Control.Monad
import Data.Semigroup
import Data.ByteString as Strict
import Data.ByteString.Lazy as Lazy
-import Data.Key as Key
import Text.Trifecta.Rope
import Text.Trifecta.Delta
import Text.Trifecta.Util.Combinators as Util
@@ -49,8 +48,6 @@ instance Functor (It r) where
fmap f (Pure a) = Pure $ f a
fmap f (It a k) = It (f a) $ fmap f . k
-type instance Key (It r) = r
-
instance Applicative (It r) where
pure = Pure
Pure f <*> Pure a = Pure $ f a
@@ -58,15 +55,9 @@ instance Applicative (It r) where
It f kf <*> Pure a = It (f a) $ fmap ($a) . kf
It f kf <*> It a ka = It (f a) $ \r -> kf r <*> ka r
-instance Indexable (It r) where
- index (Pure a) _ = a
- index (It _ k) r = extract (k r)
-
-instance Lookup (It r) where
- lookup = lookupDefault
-
-instance Zip (It r) where
- zipWith = liftA2
+indexIt :: It r a -> r -> a
+indexIt (Pure a) _ = a
+indexIt (It _ k) r = extract (k r)
simplifyIt :: It r a -> r -> It r a
simplifyIt (It _ k) r = k r
@@ -76,7 +67,7 @@ instance Monad (It r) where
return = Pure
Pure a >>= f = f a
It a k >>= f = It (extract (f a)) $ \r -> case k r of
- It a' k' -> It (Key.index (f a') r) $ k' >=> f
+ It a' k' -> It (indexIt (f a') r) $ k' >=> f
Pure a' -> simplifyIt (f a') r
instance ComonadApply (It r) where (<@>) = (<*>)
Please sign in to comment.
Something went wrong with that request. Please try again.