Skip to content

Commit 44fcdae

Browse files
committed
Move Unzip to the bottom of type-class hierarchy
Every Functor can be Unzip. Some can be more efficient than default.
1 parent 06e12cb commit 44fcdae

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# version: 0.19.20250104
11+
# version: 0.19.20250506
1212
#
13-
# REGENDATA ("0.19.20250104",["github","cabal.project"])
13+
# REGENDATA ("0.19.20250506",["github","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -23,7 +23,7 @@ on:
2323
jobs:
2424
linux:
2525
name: Haskell-CI - Linux - ${{ matrix.compiler }}
26-
runs-on: ubuntu-20.04
26+
runs-on: ubuntu-24.04
2727
timeout-minutes:
2828
60
2929
container:
@@ -91,12 +91,12 @@ jobs:
9191
- name: Install GHCup
9292
run: |
9393
mkdir -p "$HOME/.ghcup/bin"
94-
curl -sL https://downloads.haskell.org/ghcup/0.1.30.0/x86_64-linux-ghcup-0.1.30.0 > "$HOME/.ghcup/bin/ghcup"
94+
curl -sL https://downloads.haskell.org/ghcup/0.1.50.1/x86_64-linux-ghcup-0.1.50.1 > "$HOME/.ghcup/bin/ghcup"
9595
chmod a+x "$HOME/.ghcup/bin/ghcup"
9696
- name: Install cabal-install
9797
run: |
98-
"$HOME/.ghcup/bin/ghcup" install cabal 3.14.1.1 || (cat "$HOME"/.ghcup/logs/*.* && false)
99-
echo "CABAL=$HOME/.ghcup/bin/cabal-3.14.1.1 -vnormal+nowrap" >> "$GITHUB_ENV"
98+
"$HOME/.ghcup/bin/ghcup" install cabal 3.14.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
99+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.14.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
100100
- name: Install GHC (GHCup)
101101
if: matrix.setup-method == 'ghcup'
102102
run: |

semialign/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.4
2+
3+
- Reorder class hierarchy. `Unzip` is now at the bottom, right above `Functor`.
4+
15
# 1.3.1
26

37
- Support GHC-8.6.5...GHC-9.10.1

semialign/semialign.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cabal-version: >=1.10
22
name: semialign
3-
version: 1.3.1
4-
x-revision: 1
3+
version: 1.4
54
synopsis:
65
Align and Zip type-classes from the common Semialign ancestor.
76

semialign/src/Data/Semialign/Internal.hs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ oops = error . ("Data.Align: internal error: " ++)
121121
-- ≡ mapMaybe justHere (toList (align x y))
122122
-- @
123123
--
124-
class Functor f => Semialign f where
124+
class Unzip f => Semialign f where
125125
-- | Analogous to @'zip'@, combines two structures by taking the union of
126126
-- their shapes and using @'These'@ to hold the elements.
127127
align :: f a -> f b -> f (These a b)
@@ -295,7 +295,7 @@ class Zip f => Repeat f where
295295
--
296296
-- For sequence-like types this holds, but for Map-like it doesn't.
297297
--
298-
class Zip f => Unzip f where
298+
class Functor f => Unzip f where
299299
unzipWith :: (c -> (a, b)) -> f c -> (f a, f b)
300300
unzipWith f = unzip . fmap f
301301

@@ -337,6 +337,12 @@ class (ZipWithIndex i f, Repeat f) => RepeatWithIndex i f | f -> i where
337337
-- base
338338
-------------------------------------------------------------------------------
339339

340+
-- |
341+
--
342+
-- @since 1.4
343+
instance Unzip ((->) e) where
344+
unzip = unzipDefault
345+
340346
instance Semialign ((->) e) where
341347
align f g x = These (f x) (g x)
342348
alignWith h f g x = h (These (f x) (g x))
@@ -661,6 +667,13 @@ instance (RepeatWithIndex i f, RepeatWithIndex j g) => RepeatWithIndex (i, j) (C
661667
-------------------------------------------------------------------------------
662668

663669
-- Based on the Data.Vector.Fusion.Stream.Monadic zipWith implementation
670+
671+
-- |
672+
--
673+
-- @since 1.4
674+
instance Monad m => Unzip (Stream m) where
675+
unzip = unzipDefault
676+
664677
instance Monad m => Align (Stream m) where
665678
nil = Stream.empty
666679

@@ -688,9 +701,16 @@ instance Monad m => Semialign (Stream m) where
688701
_ -> Skip (sa, sb, Nothing, False)
689702
#endif
690703

704+
691705
instance Monad m => Zip (Stream m) where
692706
zipWith = Stream.zipWith
693707

708+
-- |
709+
--
710+
-- @since 1.4
711+
instance Monad m => Unzip (Bundle m v) where
712+
unzip = unzipDefault
713+
694714
instance Monad m => Align (Bundle m v) where
695715
nil = Bundle.empty
696716

0 commit comments

Comments
 (0)