Data.Monoid.Instances.Positioned

monoid-subclasses-0.4.3.1: Subclasses of Monoid

Safe Haskell | Safe
Language | Haskell2010

Data.Monoid.Instances.Positioned

Description

This module defines two monoid transformer data types, `OffsetPositioned` and `LinePositioned`. Both data types add a notion of the current position to their base monoid. In case of `OffsetPositioned`, the current position is a simple integer offset from the beginning of the monoid, and it can be applied to any `StableFactorialMonoid`. The base monoid of `LinePositioned` must be a `TextualMonoid`, but for the price it will keep track of the current line and column numbers as well.

All positions are zero-based:

    > let p = pure "abcd\nefgh\nijkl\nmnop\n" :: LinePositioned String
    > p
    Line 0, column 0: "abcd\nefgh\nijkl\nmnop\n"
    > Data.Monoid.Factorial.drop 13 p
    Line 2, column 3: "l\nmnop\n"

Synopsis

- data OffsetPositioned m
- data LinePositioned m
- extract :: Positioned p => p a -> a
- position :: Positioned p => p a -> Int
- line :: LinePositioned m -> Int
- column :: LinePositioned m -> Int

# Documentation

data OffsetPositioned m #

Instances

Functor OffsetPositioned # |
Methods fmap :: (a -> b) -> OffsetPositioned a -> OffsetPositioned b # (<$) :: a -> OffsetPositioned b -> OffsetPositioned a #
Applicative OffsetPositioned # |
Methods pure :: a -> OffsetPositioned a # (<*>) :: OffsetPositioned (a -> b) -> OffsetPositioned a -> OffsetPositioned b # (*>) :: OffsetPositioned a -> OffsetPositioned b -> OffsetPositioned b # (<*) :: OffsetPositioned a -> OffsetPositioned b -> OffsetPositioned a #
Eq m => Eq (OffsetPositioned m) # |
Methods (==) :: OffsetPositioned m -> OffsetPositioned m -> Bool # (/=) :: OffsetPositioned m -> OffsetPositioned m -> Bool #
Ord m => Ord (OffsetPositioned m) # |
Methods compare :: OffsetPositioned m -> OffsetPositioned m -> Ordering # (<) :: OffsetPositioned m -> OffsetPositioned m -> Bool # (<=) :: OffsetPositioned m -> OffsetPositioned m -> Bool # (>) :: OffsetPositioned m -> OffsetPositioned m -> Bool # (>=) :: OffsetPositioned m -> OffsetPositioned m -> Bool # max :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m # min :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m #
Show m => Show (OffsetPositioned m) # |
Methods showsPrec :: Int -> OffsetPositioned m -> ShowS # show :: OffsetPositioned m -> String # showList :: [OffsetPositioned m] -> ShowS #
IsString m => IsString (OffsetPositioned m) # |
Methods fromString :: String -> OffsetPositioned m #
StableFactorialMonoid m => Monoid (OffsetPositioned m) # |
Methods mempty :: OffsetPositioned m # mappend :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m # mconcat :: [OffsetPositioned m] -> OffsetPositioned m #
StableFactorialMonoid m => PositiveMonoid (OffsetPositioned m) # |
(StableFactorialMonoid m, MonoidNull m) => MonoidNull (OffsetPositioned m) # |
Methods null :: OffsetPositioned m -> Bool #
StableFactorialMonoid m => StableFactorialMonoid (OffsetPositioned m) # |
StableFactorialMonoid m => FactorialMonoid (OffsetPositioned m) # |
Methods factors :: OffsetPositioned m -> [OffsetPositioned m] # primePrefix :: OffsetPositioned m -> OffsetPositioned m # primeSuffix :: OffsetPositioned m -> OffsetPositioned m # splitPrimePrefix :: OffsetPositioned m -> Maybe (OffsetPositioned m, OffsetPositioned m) # splitPrimeSuffix :: OffsetPositioned m -> Maybe (OffsetPositioned m, OffsetPositioned m) # inits :: OffsetPositioned m -> [OffsetPositioned m] # tails :: OffsetPositioned m -> [OffsetPositioned m] # foldl :: (a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a # foldl' :: (a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a # foldr :: (OffsetPositioned m -> a -> a) -> a -> OffsetPositioned m -> a # length :: OffsetPositioned m -> Int # foldMap :: Monoid n => (OffsetPositioned m -> n) -> OffsetPositioned m -> n # span :: (OffsetPositioned m -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # break :: (OffsetPositioned m -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # split :: (OffsetPositioned m -> Bool) -> OffsetPositioned m -> [OffsetPositioned m] # takeWhile :: (OffsetPositioned m -> Bool) -> OffsetPositioned m -> OffsetPositioned m # dropWhile :: (OffsetPositioned m -> Bool) -> OffsetPositioned m -> OffsetPositioned m # spanMaybe :: s -> (s -> OffsetPositioned m -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) # spanMaybe' :: s -> (s -> OffsetPositioned m -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) # splitAt :: Int -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # drop :: Int -> OffsetPositioned m -> OffsetPositioned m # take :: Int -> OffsetPositioned m -> OffsetPositioned m # reverse :: OffsetPositioned m -> OffsetPositioned m #
(StableFactorialMonoid m, RightGCDMonoid m) => RightGCDMonoid (OffsetPositioned m) # |
Methods commonSuffix :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m # stripCommonSuffix :: OffsetPositioned m -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, OffsetPositioned m) #
(StableFactorialMonoid m, LeftGCDMonoid m) => LeftGCDMonoid (OffsetPositioned m) # |
Methods commonPrefix :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m # stripCommonPrefix :: OffsetPositioned m -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, OffsetPositioned m) #
(StableFactorialMonoid m, RightReductiveMonoid m) => RightReductiveMonoid (OffsetPositioned m) # |
Methods isSuffixOf :: OffsetPositioned m -> OffsetPositioned m -> Bool # stripSuffix :: OffsetPositioned m -> OffsetPositioned m -> Maybe (OffsetPositioned m) #
(StableFactorialMonoid m, LeftReductiveMonoid m) => LeftReductiveMonoid (OffsetPositioned m) # |
Methods isPrefixOf :: OffsetPositioned m -> OffsetPositioned m -> Bool # stripPrefix :: OffsetPositioned m -> OffsetPositioned m -> Maybe (OffsetPositioned m) #
(StableFactorialMonoid m, TextualMonoid m) => TextualMonoid (OffsetPositioned m) # |
Methods fromText :: Text -> OffsetPositioned m # singleton :: Char -> OffsetPositioned m # splitCharacterPrefix :: OffsetPositioned m -> Maybe (Char, OffsetPositioned m) # characterPrefix :: OffsetPositioned m -> Maybe Char # map :: (Char -> Char) -> OffsetPositioned m -> OffsetPositioned m # concatMap :: (Char -> OffsetPositioned m) -> OffsetPositioned m -> OffsetPositioned m # toString :: (OffsetPositioned m -> String) -> OffsetPositioned m -> String # any :: (Char -> Bool) -> OffsetPositioned m -> Bool # all :: (Char -> Bool) -> OffsetPositioned m -> Bool # foldl :: (a -> OffsetPositioned m -> a) -> (a -> Char -> a) -> a -> OffsetPositioned m -> a # foldl' :: (a -> OffsetPositioned m -> a) -> (a -> Char -> a) -> a -> OffsetPositioned m -> a # foldr :: (OffsetPositioned m -> a -> a) -> (Char -> a -> a) -> a -> OffsetPositioned m -> a # scanl :: (Char -> Char -> Char) -> Char -> OffsetPositioned m -> OffsetPositioned m # scanl1 :: (Char -> Char -> Char) -> OffsetPositioned m -> OffsetPositioned m # scanr :: (Char -> Char -> Char) -> Char -> OffsetPositioned m -> OffsetPositioned m # scanr1 :: (Char -> Char -> Char) -> OffsetPositioned m -> OffsetPositioned m # mapAccumL :: (a -> Char -> (a, Char)) -> a -> OffsetPositioned m -> (a, OffsetPositioned m) # mapAccumR :: (a -> Char -> (a, Char)) -> a -> OffsetPositioned m -> (a, OffsetPositioned m) # takeWhile :: (OffsetPositioned m -> Bool) -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m # dropWhile :: (OffsetPositioned m -> Bool) -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m # break :: (OffsetPositioned m -> Bool) -> (Char -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # span :: (OffsetPositioned m -> Bool) -> (Char -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # spanMaybe :: s -> (s -> OffsetPositioned m -> Maybe s) -> (s -> Char -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) # spanMaybe' :: s -> (s -> OffsetPositioned m -> Maybe s) -> (s -> Char -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) # split :: (Char -> Bool) -> OffsetPositioned m -> [OffsetPositioned m] # find :: (Char -> Bool) -> OffsetPositioned m -> Maybe Char # elem :: Char -> OffsetPositioned m -> Bool # foldl_ :: (a -> Char -> a) -> a -> OffsetPositioned m -> a # foldl_' :: (a -> Char -> a) -> a -> OffsetPositioned m -> a # foldr_ :: (Char -> a -> a) -> a -> OffsetPositioned m -> a # takeWhile_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m # dropWhile_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m # break_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # span_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m) # spanMaybe_ :: s -> (s -> Char -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) # spanMaybe_' :: s -> (s -> Char -> Maybe s) -> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m, s) #

data LinePositioned m #

Instances

Functor LinePositioned # |
Methods fmap :: (a -> b) -> LinePositioned a -> LinePositioned b # (<$) :: a -> LinePositioned b -> LinePositioned a #
Applicative LinePositioned # |
Methods pure :: a -> LinePositioned a # (<*>) :: LinePositioned (a -> b) -> LinePositioned a -> LinePositioned b # (*>) :: LinePositioned a -> LinePositioned b -> LinePositioned b # (<*) :: LinePositioned a -> LinePositioned b -> LinePositioned a #
Eq m => Eq (LinePositioned m) # |
Methods (==) :: LinePositioned m -> LinePositioned m -> Bool # (/=) :: LinePositioned m -> LinePositioned m -> Bool #
Ord m => Ord (LinePositioned m) # |
Methods compare :: LinePositioned m -> LinePositioned m -> Ordering # (<) :: LinePositioned m -> LinePositioned m -> Bool # (<=) :: LinePositioned m -> LinePositioned m -> Bool # (>) :: LinePositioned m -> LinePositioned m -> Bool # (>=) :: LinePositioned m -> LinePositioned m -> Bool # max :: LinePositioned m -> LinePositioned m -> LinePositioned m # min :: LinePositioned m -> LinePositioned m -> LinePositioned m #
Show m => Show (LinePositioned m) # |
Methods showsPrec :: Int -> LinePositioned m -> ShowS # show :: LinePositioned m -> String # showList :: [LinePositioned m] -> ShowS #
IsString m => IsString (LinePositioned m) # |
Methods fromString :: String -> LinePositioned m #
(StableFactorialMonoid m, TextualMonoid m) => Monoid (LinePositioned m) # |
Methods mempty :: LinePositioned m # mappend :: LinePositioned m -> LinePositioned m -> LinePositioned m # mconcat :: [LinePositioned m] -> LinePositioned m #
(StableFactorialMonoid m, TextualMonoid m) => PositiveMonoid (LinePositioned m) # |
(StableFactorialMonoid m, TextualMonoid m, MonoidNull m) => MonoidNull (LinePositioned m) # |
Methods null :: LinePositioned m -> Bool #
(StableFactorialMonoid m, TextualMonoid m) => StableFactorialMonoid (LinePositioned m) # |
(StableFactorialMonoid m, TextualMonoid m) => FactorialMonoid (LinePositioned m) # |
Methods factors :: LinePositioned m -> [LinePositioned m] # primePrefix :: LinePositioned m -> LinePositioned m # primeSuffix :: LinePositioned m -> LinePositioned m # splitPrimePrefix :: LinePositioned m -> Maybe (LinePositioned m, LinePositioned m) # splitPrimeSuffix :: LinePositioned m -> Maybe (LinePositioned m, LinePositioned m) # inits :: LinePositioned m -> [LinePositioned m] # tails :: LinePositioned m -> [LinePositioned m] # foldl :: (a -> LinePositioned m -> a) -> a -> LinePositioned m -> a # foldl' :: (a -> LinePositioned m -> a) -> a -> LinePositioned m -> a # foldr :: (LinePositioned m -> a -> a) -> a -> LinePositioned m -> a # length :: LinePositioned m -> Int # foldMap :: Monoid n => (LinePositioned m -> n) -> LinePositioned m -> n # span :: (LinePositioned m -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # break :: (LinePositioned m -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # split :: (LinePositioned m -> Bool) -> LinePositioned m -> [LinePositioned m] # takeWhile :: (LinePositioned m -> Bool) -> LinePositioned m -> LinePositioned m # dropWhile :: (LinePositioned m -> Bool) -> LinePositioned m -> LinePositioned m # spanMaybe :: s -> (s -> LinePositioned m -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) # spanMaybe' :: s -> (s -> LinePositioned m -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) # splitAt :: Int -> LinePositioned m -> (LinePositioned m, LinePositioned m) # drop :: Int -> LinePositioned m -> LinePositioned m # take :: Int -> LinePositioned m -> LinePositioned m # reverse :: LinePositioned m -> LinePositioned m #
(StableFactorialMonoid m, TextualMonoid m, RightGCDMonoid m) => RightGCDMonoid (LinePositioned m) # |
Methods commonSuffix :: LinePositioned m -> LinePositioned m -> LinePositioned m # stripCommonSuffix :: LinePositioned m -> LinePositioned m -> (LinePositioned m, LinePositioned m, LinePositioned m) #
(StableFactorialMonoid m, TextualMonoid m, LeftGCDMonoid m) => LeftGCDMonoid (LinePositioned m) # |
Methods commonPrefix :: LinePositioned m -> LinePositioned m -> LinePositioned m # stripCommonPrefix :: LinePositioned m -> LinePositioned m -> (LinePositioned m, LinePositioned m, LinePositioned m) #
(StableFactorialMonoid m, TextualMonoid m, RightReductiveMonoid m) => RightReductiveMonoid (LinePositioned m) # |
Methods isSuffixOf :: LinePositioned m -> LinePositioned m -> Bool # stripSuffix :: LinePositioned m -> LinePositioned m -> Maybe (LinePositioned m) #
(StableFactorialMonoid m, TextualMonoid m, LeftReductiveMonoid m) => LeftReductiveMonoid (LinePositioned m) # |
Methods isPrefixOf :: LinePositioned m -> LinePositioned m -> Bool # stripPrefix :: LinePositioned m -> LinePositioned m -> Maybe (LinePositioned m) #
(StableFactorialMonoid m, TextualMonoid m) => TextualMonoid (LinePositioned m) # |
Methods fromText :: Text -> LinePositioned m # singleton :: Char -> LinePositioned m # splitCharacterPrefix :: LinePositioned m -> Maybe (Char, LinePositioned m) # characterPrefix :: LinePositioned m -> Maybe Char # map :: (Char -> Char) -> LinePositioned m -> LinePositioned m # concatMap :: (Char -> LinePositioned m) -> LinePositioned m -> LinePositioned m # toString :: (LinePositioned m -> String) -> LinePositioned m -> String # any :: (Char -> Bool) -> LinePositioned m -> Bool # all :: (Char -> Bool) -> LinePositioned m -> Bool # foldl :: (a -> LinePositioned m -> a) -> (a -> Char -> a) -> a -> LinePositioned m -> a # foldl' :: (a -> LinePositioned m -> a) -> (a -> Char -> a) -> a -> LinePositioned m -> a # foldr :: (LinePositioned m -> a -> a) -> (Char -> a -> a) -> a -> LinePositioned m -> a # scanl :: (Char -> Char -> Char) -> Char -> LinePositioned m -> LinePositioned m # scanl1 :: (Char -> Char -> Char) -> LinePositioned m -> LinePositioned m # scanr :: (Char -> Char -> Char) -> Char -> LinePositioned m -> LinePositioned m # scanr1 :: (Char -> Char -> Char) -> LinePositioned m -> LinePositioned m # mapAccumL :: (a -> Char -> (a, Char)) -> a -> LinePositioned m -> (a, LinePositioned m) # mapAccumR :: (a -> Char -> (a, Char)) -> a -> LinePositioned m -> (a, LinePositioned m) # takeWhile :: (LinePositioned m -> Bool) -> (Char -> Bool) -> LinePositioned m -> LinePositioned m # dropWhile :: (LinePositioned m -> Bool) -> (Char -> Bool) -> LinePositioned m -> LinePositioned m # break :: (LinePositioned m -> Bool) -> (Char -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # span :: (LinePositioned m -> Bool) -> (Char -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # spanMaybe :: s -> (s -> LinePositioned m -> Maybe s) -> (s -> Char -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) # spanMaybe' :: s -> (s -> LinePositioned m -> Maybe s) -> (s -> Char -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) # split :: (Char -> Bool) -> LinePositioned m -> [LinePositioned m] # find :: (Char -> Bool) -> LinePositioned m -> Maybe Char # elem :: Char -> LinePositioned m -> Bool # foldl_ :: (a -> Char -> a) -> a -> LinePositioned m -> a # foldl_' :: (a -> Char -> a) -> a -> LinePositioned m -> a # foldr_ :: (Char -> a -> a) -> a -> LinePositioned m -> a # takeWhile_ :: Bool -> (Char -> Bool) -> LinePositioned m -> LinePositioned m # dropWhile_ :: Bool -> (Char -> Bool) -> LinePositioned m -> LinePositioned m # break_ :: Bool -> (Char -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # span_ :: Bool -> (Char -> Bool) -> LinePositioned m -> (LinePositioned m, LinePositioned m) # spanMaybe_ :: s -> (s -> Char -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) # spanMaybe_' :: s -> (s -> Char -> Maybe s) -> LinePositioned m -> (LinePositioned m, LinePositioned m, s) #

extract :: Positioned p => p a -> a #

position :: Positioned p => p a -> Int #

line :: LinePositioned m -> Int #

the current line

column :: LinePositioned m -> Int #

the current column