Skip to content

Add instance AsType a a #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions generic-lens/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
- Add `instance AsType a a`

## generic-lens-2.2.2.0 (2023-04-15)
- Support unprefixed constructor prisms on GHC 9.6 (#152)

Expand Down
3 changes: 2 additions & 1 deletion generic-lens/generic-lens.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ test-suite inspection-tests
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 CustomChildren
other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 Test146 CustomChildren

build-depends: base >= 4.11 && <= 5.0
, generic-lens
, lens
, mtl
, profunctors
, inspection-testing >= 0.2
, HUnit
Expand Down
4 changes: 4 additions & 0 deletions generic-lens/src/Data/Generics/Sum/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class AsType a s where

{-# MINIMAL (injectTyped, projectTyped) | _Typed #-}

instance {-# OVERLAPPING #-} AsType a a where
injectTyped = id
projectTyped = Just

instance Core.Context a s => AsType a s where
_Typed eta = prism2prismvl Core.derived eta
{-# INLINE _Typed #-}
Expand Down
1 change: 1 addition & 0 deletions generic-lens/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Data.Generics.Labels ()
import Test24 ()
import Test25 ()
import Test88 ()
import Test146 ()

import CustomChildren (customTypesTest)

Expand Down
19 changes: 19 additions & 0 deletions generic-lens/test/Test146.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}

module Test146 where

import Control.Monad.Except
import Data.Generics.Sum
import GHC.Generics

data Error = Error
deriving (Generic)

poly :: (AsType Error e, MonadError e m) => m ()
poly = undefined

mono :: ExceptT Error IO ()
mono = poly


3 changes: 3 additions & 0 deletions generic-optics/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
- Add `instance AsType a a`

## generic-optics-2.2.1.0 (2022-01-22)
- GHC 9.2 compatibility

Expand Down
3 changes: 2 additions & 1 deletion generic-optics/generic-optics.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ test-suite generic-optics-inspection-tests
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 CustomChildren
other-modules: Util Test24 Test88 Test25 Test40 Test62 Test63 Test146 CustomChildren

build-depends: base >= 4.11 && <= 5.0
, generic-optics
, mtl
, optics-core
, inspection-testing >= 0.2
, HUnit
Expand Down
4 changes: 4 additions & 0 deletions generic-optics/src/Data/Generics/Sum/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class AsType a s where

{-# MINIMAL (injectTyped, projectTyped) | _Typed #-}

instance {-# OVERLAPPING #-} AsType a a where
injectTyped = id
projectTyped = Just

instance Core.Context a s => AsType a s where
_Typed = normalisePrism (Optic Core.derived)
{-# INLINE _Typed #-}
Expand Down
1 change: 1 addition & 0 deletions generic-optics/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Optics.Core
-- This is sufficient at we only want to test that they typecheck
import Test24 ()
import Test25 ()
import Test146 ()

-- import CustomChildren (customTypesTest)

Expand Down
20 changes: 20 additions & 0 deletions generic-optics/test/Test146.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}

module Test146 where

import Control.Monad.Except
import Data.Generics.Sum
import GHC.Generics

data Error = Error
deriving (Generic)

poly :: (AsType Error e, MonadError e m) => m ()
poly = undefined

mono :: ExceptT Error IO ()
mono = poly