first-class-instances-0.1.0.0: First class typeclass instances

Safe HaskellNone
LanguageHaskell2010

FCI.Internal.Definitions

Description

Core definitions. This module is internal and provides no guarantees about stability and safety of it's interface.

Synopsis

Documentation

type Inst c = Inst c Source #

Type that maps constraint to it's representation. You can get hold of representation of some special constraints and classes that use mkInst.

For example:

class Bar a => Foo a where
  baz :: a
  qux :: a -> b -> [(a, b)]

mkInst 'Foo

creates datatype instance:

type instance Inst (Foo a) = Dict (Foo a)
data instance Dict (Foo a) = Foo{
    _Bar :: Inst (Bar a)
  , baz  :: a
  , qux  :: forall b. a -> b -> [(a, b)]
  }

You can get hold of representation of global instance using inst. You are free to modify and read it and you can use (==>) to apply it as constraint in context of some subexpression. See mkInst for more info about format of generated representation.

type Dict = Dict Source #

Type of representation of class instance. You can get instance for your class using mkInst and access value of global instance using inst. Prefer Inst in signatures when working with constraint representations.

inst :: forall c. c => Inst c Source #

Reflects constraint into correspoding representation - can be used to access normal class instances from the environment. This function is meant to be used with TypeApplications when it's usage is ambiguous.

TODO: example

(==>) :: forall c r. Inst c -> (c => r) -> r infixr 0 Source #

Reifies first class instance into constraint in context of supplied continuation.

For example:

>>> newtype Foo a = Foo a deriving Show
>>> coerceFunctor @Foo ==> (+1) <$> Foo 1
Foo 2

type Newtype f = forall a. (Coercible a (f a), Coercible (f a) a) Source #

Allows to coerce type back and forth between it's argument when safe.