HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerebase-1.21.2Haskell2010

Rebase.Data.Profunctor.Unsafe

  • 1 class
  • Packagerebase-1.21.2
  • Exports1
  • LanguageHaskell2010
  • LicenceMIT
  • SourceUnsafe.hs
classclass Profunctor (p :: Type -> Type -> Type) where
#

Formally, the class Profunctor represents a profunctor from Hask -> Hask.

Intuitively it is a bifunctor where the first argument is contravariant and the second argument is covariant.

You can define a Profunctor by either defining dimap or by defining both lmap and rmap.

If you supply dimap, you should ensure that:

dimap id id ≡ id

If you supply lmap and rmap, ensure:

lmap id ≡ id
rmap id ≡ id

If you supply both, you should also ensure:

dimap f g ≡ lmap f . rmap g

These ensure by parametricity:

dimap (f . g) (h . i) ≡ dimap g h . dimap f i
lmap (f . g) ≡ lmap g . lmap f
rmap (f . g) ≡ rmap f . rmap g

Methods

  • dimap :: (a -> b) -> (c -> d) -> p b c -> p a d

    Map over both arguments at the same time.

    dimap f g ≡ lmap f . rmap g
  • lmap :: (a -> b) -> p b c -> p a c

    Map the first argument contravariantly.

    lmap f ≡ dimap f id
  • rmap :: (b -> c) -> p a b -> p a c

    Map the second argument covariantly.

    rmap ≡ dimap id
  • (#.) :: Coercible c b => q b c -> p a b -> p a cinfixr 9

    Strictly map the second argument argument covariantly with a function that is assumed operationally to be a cast, such as a newtype constructor.

    Note: This operation is explicitly unsafe since an implementation may choose to use unsafeCoerce to implement this combinator and it has no way to validate that your function meets the requirements.

    If you implement this combinator with unsafeCoerce, then you are taking upon yourself the obligation that you don't use GADT-like tricks to distinguish values.

    If you import Data.Profunctor.Unsafe you are taking upon yourself the obligation that you will only call this with a first argument that is operationally identity.

    The semantics of this function with respect to bottoms should match the default definition:

    (Profuctor.Unsafe.#.) ≡ \_ -> \p -> p `seq` rmap coerce p
  • (.#) :: Coercible b a => p b c -> q a b -> p a cinfixl 8

    Strictly map the first argument argument contravariantly with a function that is assumed operationally to be a cast, such as a newtype constructor.

    Note: This operation is explicitly unsafe since an implementation may choose to use unsafeCoerce to implement this combinator and it has no way to validate that your function meets the requirements.

    If you implement this combinator with unsafeCoerce, then you are taking upon yourself the obligation that you don't use GADT-like tricks to distinguish values.

    If you import Data.Profunctor.Unsafe you are taking upon yourself the obligation that you will only call this with a second argument that is operationally identity.

    (.#) ≡ \p -> p `seq` \f -> lmap coerce p
Instances38Profunctor, …