diff --git a/Data/Patch/Internal.hs b/Data/Patch/Internal.hs index 30c3b5b..3784b12 100644 --- a/Data/Patch/Internal.hs +++ b/Data/Patch/Internal.hs @@ -1,7 +1,8 @@ {-# LANGUAGE BangPatterns, Trustworthy #-} -- | For day-to-day use, please see "Data.Patch" module Data.Patch.Internal where -import Data.Monoid +import Data.Monoid hiding ((<>)) +import Data.Semigroup (Semigroup (..)) import Data.Ord import qualified Data.List as List import qualified Data.Vector as Vector @@ -145,9 +146,8 @@ normalise grp = let (inserts, deletes, replaces) = partition3 grp normalise' [] (d:_) _ = [d] normalise' _ _ _ = error "Impossible!" -instance Eq a => Monoid (Patch a) where - mempty = Patch [] - mappend (Patch a) (Patch b) = Patch $ merge a b (0 :: Int) +instance Eq a => Semigroup (Patch a) where + (<>) (Patch a) (Patch b) = Patch $ merge a b (0 :: Int) where merge [] ys off = map (over index (+ off)) ys merge xs [] _ = xs @@ -171,6 +171,10 @@ instance Eq a => Monoid (Patch a) where replace _ o n | o == n = id replace i o n | otherwise = (Replace i o n :) +instance Eq a => Monoid (Patch a) where + mempty = Patch [] + mappend = (<>) + -- | Returns true if a patch can be safely applied to a document, that is, -- @applicable p d@ holds when @d@ is a valid source document for the patch @p@. applicable :: (Eq a) => Patch a -> Vector a -> Bool @@ -317,7 +321,7 @@ theirs :: a -> a -> a theirs = flip const -- | A convenience version of 'transformWith' which resolves conflicts using 'mappend'. -transform :: (Eq a, Monoid a) => Patch a -> Patch a -> (Patch a, Patch a) +transform :: (Eq a, Semigroup a) => Patch a -> Patch a -> (Patch a, Patch a) transform = transformWith (<>) -- | Compute the difference between two documents, using the Wagner-Fischer algorithm. O(mn) time and space. diff --git a/patches-vector.cabal b/patches-vector.cabal index 8df1800..69d1809 100644 --- a/patches-vector.cabal +++ b/patches-vector.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: patches-vector -version: 0.1.5.4 +version: 0.1.6 synopsis: Patches (diffs) on vectors: composable, mergeable, and invertible. description: A patch is a collection of modifications (edits) to be made to a sequence of elements. Commonly found in version control systems, patches are also a simple example of a groupoid, supporting (partial) composition @@ -33,7 +33,7 @@ library , Data.Patch.Internal build-depends: base >=4.7 && <5 , edit-distance-vector >=1.0 && <1.1 - , vector >= 0.10 && < 0.12 + , vector >= 0.10 && < 0.13 , microlens >= 0.2 && < 0.5 default-language: Haskell2010 @@ -41,9 +41,9 @@ test-suite doctest-patches-vector type: exitcode-stdio-1.0 main-is: doctest.hs build-depends: base >= 4.7 && < 5 - , QuickCheck >= 2.7 && < 2.9 + , QuickCheck >= 2.7 && < 2.12 , patches-vector - , doctest >= 0.9 && < 0.12 + , doctest >= 0.9 && < 0.17 default-language: Haskell2010 test-suite benchmarks-patches-vector @@ -51,10 +51,10 @@ test-suite benchmarks-patches-vector main-is: benchmarks.hs hs-source-dirs: bm build-depends: base >= 4.7 && < 5 - , QuickCheck >= 2.7 && < 2.9 + , QuickCheck >= 2.7 && < 2.12 , patches-vector - , criterion >= 1.1 && < 1.2 - , vector >= 0.10 && <0.12 + , criterion >= 1.1 && < 1.45 + , vector >= 0.10 && <0.13 default-language: Haskell2010 test-suite spec-patches-vector @@ -65,9 +65,9 @@ test-suite spec-patches-vector , Test.Util , Test.UtilSpec build-depends: base >= 4.7 && < 5 - , QuickCheck >= 2.7 && < 2.9 + , QuickCheck >= 2.7 && < 2.12 , patches-vector - , criterion >= 1.1 && < 1.2 - , vector >= 0.10 && <0.12 - , hspec >= 2.1 && < 2.3 + , criterion >= 1.1 && < 1.5 + , vector >= 0.10 && <0.13 + , hspec >= 2.1 && < 2.6 default-language: Haskell2010 diff --git a/stack.yaml b/stack.yaml index f29c7cf..90ac275 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,32 +1,7 @@ -# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md +resolver: lts-12.4 -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-7.10 - -# Local packages, usually specified by relative directory name packages: - '.' -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) extra-deps: - edit-distance-vector-1.0.0.4 -# Override default flag values for local packages and extra-deps -flags: {} - -# Extra package databases containing global packages -extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 0.1.4.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir]