Skip to content

Commit

Permalink
* Add Bifunctor instance suggested by Jonathan King
Browse files Browse the repository at this point in the history
* Require base >= 4.8 for class Bifunctor
  • Loading branch information
ddssff committed Oct 9, 2023
1 parent 319ab04 commit 969fb27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
0.4
# 0.5

* Generalize `Diff a` to `PolyDiff a b`. `Diff` has been replaced with
a specialized synonym `type Diff a = PolyDiff a a`, but it's still not
backward compatible if you imported `Diff(..)`.
- Bring space complexity down to D^2 (Bodigrim)
- Add Bifunctor instance (Jonathan King.) Requires base >= 4.8.
- Fix for the grouped context diff. It was omitting all trailing
context.
- Allow unlimited number of context elements (getContextDiffNew)

# 0.4

- Generalize `Diff a` to `PolyDiff a b`. `Diff` has been replaced with
a specialized synonym `type Diff a = PolyDiff a a`, but it's still not
backward compatible if you imported `Diff(..)`.
2 changes: 1 addition & 1 deletion Diff.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Cabal-Version: >= 1.10

library
default-language: Haskell2010
build-depends: base >= 3 && <= 6, array, pretty >= 1.1
build-depends: base >= 4.8 && <= 6, array, pretty >= 1.1
hs-source-dirs: src
exposed-modules:
Data.Algorithm.Diff,
Expand Down
7 changes: 6 additions & 1 deletion src/Data/Algorithm/Diff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ module Data.Algorithm.Diff
) where

import Prelude hiding (pi)

import Data.Array (listArray, (!))
import Data.Bifunctor

data DI = F | S deriving (Show, Eq)

Expand All @@ -38,6 +38,11 @@ data DI = F | S deriving (Show, Eq)
data PolyDiff a b = First a | Second b | Both a b
deriving (Show, Eq)

instance Bifunctor PolyDiff where
bimap f _ (First a) = First (f a)
bimap _ g (Second b) = Second (g b)
bimap f g (Both a b) = Both (f a) (g b)

-- | This is 'PolyDiff' specialized so both sides are the same type.
type Diff a = PolyDiff a a

Expand Down

0 comments on commit 969fb27

Please sign in to comment.