Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.19.20250506
# version: 0.19.20251211
#
# REGENDATA ("0.19.20250506",["github","newtype.cabal"])
# REGENDATA ("0.19.20251211",["github","newtype.cabal"])
#
name: Haskell-CI
on:
Expand All @@ -20,6 +20,9 @@ on:
pull_request:
branches:
- master
merge_group:
branches:
- master
jobs:
linux:
name: Haskell-CI - Linux - ${{ matrix.compiler }}
Expand All @@ -32,14 +35,19 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.14.0.20251128
compilerKind: ghc
compilerVersion: 9.14.0.20251128
setup-method: ghcup-prerelease
allow-failure: false
- compiler: ghc-9.12.2
compilerKind: ghc
compilerVersion: 9.12.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.10.2
- compiler: ghc-9.10.3
compilerKind: ghc
compilerVersion: 9.10.2
compilerVersion: 9.10.3
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.8.4
Expand Down Expand Up @@ -110,8 +118,8 @@ jobs:
chmod a+x "$HOME/.ghcup/bin/ghcup"
- name: Install cabal-install
run: |
"$HOME/.ghcup/bin/ghcup" install cabal 3.14.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
echo "CABAL=$HOME/.ghcup/bin/cabal-3.14.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
"$HOME/.ghcup/bin/ghcup" install cabal 3.16.0.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
echo "CABAL=$HOME/.ghcup/bin/cabal-3.16.0.0 -vnormal+nowrap" >> "$GITHUB_ENV"
- name: Install GHC (GHCup)
if: matrix.setup-method == 'ghcup'
run: |
Expand All @@ -126,6 +134,21 @@ jobs:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Install GHC (GHCup prerelease)
if: matrix.setup-method == 'ghcup-prerelease'
run: |
"$HOME/.ghcup/bin/ghcup" config add-release-channel prereleases
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Set PATH and environment variables
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
Expand All @@ -136,7 +159,7 @@ jobs:
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
if [ $((HCNUMVER >= 91400)) -ne 0 ] ; then echo "HEADHACKAGE=true" >> "$GITHUB_ENV" ; else echo "HEADHACKAGE=false" >> "$GITHUB_ENV" ; fi
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
Expand Down Expand Up @@ -164,6 +187,18 @@ jobs:
repository hackage.haskell.org
url: http://hackage.haskell.org/
EOF
if $HEADHACKAGE; then
cat >> $CABAL_CONFIG <<EOF
repository head.hackage.ghc.haskell.org
url: https://ghc.gitlab.haskell.org/head.hackage/
secure: True
root-keys: 7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
key-threshold: 3
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org:override
EOF
fi
cat >> $CABAL_CONFIG <<EOF
program-default-options
ghc-options: $GHCJOBS +RTS -M3G -RTS
Expand All @@ -187,7 +222,7 @@ jobs:
chmod a+x $HOME/.cabal/bin/cabal-plan
cabal-plan --version
- name: checkout
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
path: source
- name: initial cabal.project for sdist
Expand All @@ -212,9 +247,16 @@ jobs:
touch cabal.project.local
echo "packages: ${PKGDIR_newtype}" >> cabal.project
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package newtype" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods -Werror=missing-fields" >> cabal.project ; fi
if [ $((HCNUMVER >= 90400)) -ne 0 ] ; then echo "package newtype" >> cabal.project ; fi
if [ $((HCNUMVER >= 90400)) -ne 0 ] ; then echo " ghc-options: -Werror=unused-packages" >> cabal.project ; fi
if [ $((HCNUMVER >= 90000)) -ne 0 ] ; then echo "package newtype" >> cabal.project ; fi
if [ $((HCNUMVER >= 90000)) -ne 0 ] ; then echo " ghc-options: -Werror=incomplete-patterns -Werror=incomplete-uni-patterns" >> cabal.project ; fi
cat >> cabal.project <<EOF
EOF
if $HEADHACKAGE; then
echo "allow-newer: $($HCPKG list --simple-output | sed -E 's/([a-zA-Z-]+)-[0-9.]+/*:\1,/g')" >> cabal.project
fi
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(newtype)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
See also https://pvp.haskell.org/faq
## 0.2.2.1

- Drop support for GHC 7.
- Tested with GHC 8.0 - 9.14.

## 0.2.2.0

Expand Down
37 changes: 4 additions & 33 deletions Control/Newtype.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE DefaultSignatures #-}
#endif

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}

{- |
Module : Control.Newtype
Expand Down Expand Up @@ -42,19 +40,14 @@ module Control.Newtype

import Control.Applicative
import Control.Arrow

import Data.Coerce
import Data.Fixed
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Monoid
import Data.Ord

#if !MIN_VERSION_base(4,7,0)
-- necessary evil for 'Newtype Fixed'
import Unsafe.Coerce (unsafeCoerce)
#else
import Data.Coerce
#endif

-- | Given a @newtype@ @n@, we will always have the same unwrapped type @o@, meaning we can represent this with a fundep @n -> o@.
--
-- Any instance of this class just needs to let 'pack' equal to the newtype's constructor, and let 'unpack' destruct the @newtype@ with pattern matching.
Expand All @@ -72,23 +65,11 @@ class Newtype n o | n -> o where

unpack :: n -> o

#if __GLASGOW_HASKELL__ >= 704
default pack :: Coercible o n => o -> n
pack = coerce

default unpack :: Coercible n o => n -> o
unpack = coerce
#endif

#if __GLASGOW_HASKELL__ >= 704 && !MIN_VERSION_base(4,7,0)
-- Hack: We define a dummy 'Coercible' class to force a
-- missing-instance compile error when methods are not explicitly
-- defined
class Coercible o n

coerce :: a -> b
coerce = undefined
#endif

{- TODO: for newtype-0.3

Expand Down Expand Up @@ -196,37 +177,27 @@ instance ArrowApply a => Newtype (ArrowMonad a b) (a () b) where

-- | @since 0.2.1.0
instance Newtype (Fixed a) Integer where
#if MIN_VERSION_base(4,7,0)
pack = MkFixed
unpack (MkFixed x) = x
#else
-- 'Fixed' is a newtype, but its constructor wasn't exported before base-4.7.0
pack = unsafeCoerce
unpack = unsafeCoerce
#endif

-- | @since 0.2.1.0
instance Newtype (Dual a) a where
pack = Dual
unpack (Dual a) = a

#if MIN_VERSION_base(4,8,0)
-- | __NOTE__: Type & instance only available with @base ≥ 4.8.0@
--
-- @since 0.2.1.0
instance Newtype (Alt f a) (f a) where
pack = Alt
unpack (Alt x) = x
#endif

#if MIN_VERSION_base(4,6,0)
-- | __NOTE__: Type & instance only available with @base ≥ 4.6.0@
--
-- @since 0.2.1.0
instance Newtype (Down a) a where
pack = Down
unpack (Down a) = a
#endif

-- | @since 0.2.1.0
instance Newtype (Identity a) a where
Expand Down
19 changes: 8 additions & 11 deletions newtype.cabal
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cabal-version: 1.12
build-type: Simple
name: newtype
version: 0.2.2.0
x-revision: 3
version: 0.2.2.1

license: BSD3
license-file: LICENSE
Expand All @@ -15,8 +14,9 @@ synopsis: A typeclass and set of functions for working with newtypes.
description: Per Conor McBride, the 'Newtype' typeclass represents the packing and unpacking of a @newtype@, and allows you to operate under that @newtype@ with functions such as 'ala'. See "Control.Newtype" for documentation and examples.

tested-with:
GHC == 9.14.1
GHC == 9.12.2
GHC == 9.10.2
GHC == 9.10.3
GHC == 9.8.4
GHC == 9.6.7
GHC == 9.4.8
Expand All @@ -38,20 +38,17 @@ source-repository head
library
exposed-modules: Control.Newtype

build-depends: base >= 4.3 && < 5
if !impl(ghc >= 8.0)
build-depends: transformers >= 0.2.2.0 && < 0.6
build-depends: base >= 4.9 && < 5

default-language: Haskell2010
other-extensions:
CPP
FlexibleInstances
FunctionalDependencies
MultiParamTypeClasses
Trustworthy
TypeFamilies

if impl(ghc >= 7.2)
default-extensions: Trustworthy
if impl(ghc >= 7.10) { ghc-options: -fno-warn-trustworthy-safe }

ghc-options: -Wall
ghc-options:
-Wall
-Wno-trustworthy-safe