Skip to content

Commit

Permalink
Merge pull request #325 from well-typed/324-fix
Browse files Browse the repository at this point in the history
Optimize away profunctor classes when profiling (#324)
  • Loading branch information
arybczak committed Jun 29, 2020
2 parents 235b206 + 0a79e82 commit 62e01ff
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions optics-core/src/Optics/Internal/Optic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Optics.Internal.Optic
, Optic'
, Optic_
, Optic__
, getOptic
, castOptic
, (%)
, (%%)
Expand Down Expand Up @@ -66,10 +67,19 @@ import Unsafe.Coerce (unsafeCoerce)
-- The parameters @s@ and @t@ represent the "big" structure,
-- whereas @a@ and @b@ represent the "small" structure.
--
newtype Optic (k :: OpticKind) (is :: IxList) s t a b = Optic
{ getOptic :: forall p i. Profunctor p
=> Optic_ k p i (Curry is i) s t a b
}
newtype Optic (k :: OpticKind) (is :: IxList) s t a b
= Optic (forall p i. Profunctor p => Optic_ k p i (Curry is i) s t a b)

-- | Strip the newtype wrapper off.
getOptic
:: Profunctor p
=> Optic k is s t a b
-> Optic_ k p i (Curry is i) s t a b
-- Note: This is not part of the definition of 'Optic' because it needs to be
-- marked INLINE for GHC to optimize away profunctor classes when profiling.
-- See https://github.com/well-typed/optics/issues/324 for more details.
getOptic (Optic o) = o
{-# INLINE getOptic #-}

-- | Common special case of 'Optic' where source and target types are equal.
--
Expand Down

0 comments on commit 62e01ff

Please sign in to comment.