impl-0.1.0.0: Framework for defaulting superclasses

Safe HaskellNone
LanguageHaskell2010
Extensions
  • MonoLocalBinds
  • TemplateHaskell
  • TemplateHaskellQuotes
  • AllowAmbiguousTypes
  • TypeFamilies
  • ViewPatterns
  • PolyKinds
  • DataKinds
  • KindSignatures
  • TypeOperators
  • ExplicitNamespaces
  • OverloadedLabels
  • TypeApplications

Impl

Contents

Description

This small but extensible framework facilitates defining complex defaulting rules that are not handled by DefaultSignatures, and reducing the overhead of giving instances to new datatypes by generating superclasses. One reason we might want this is when a superclass wants to be given a default by two different subclasses (ex: Bifunctor and Profunctor both could generate Functor instances). See the example internal library for how to implement instances of Impl.

Synopsis

Documentation

class Impl c where Source #

Associated Types

type Methods c :: [Symbol] Source #

Methods

impl :: TypeQ -> NamedMethods c :-> DecsQ Source #

Instantiate the implementing class along with all its superclasses Ex:

impl @Monad [t|[]|]
  ! #return [|\x -> [x]|]
  ! #bind   [|flip concatMap|]

type NamedMethods c = NamedExpQ (Methods c) Source #

Named TH Exps for the class method implementations

Reexports

type family as :-> r where ... infixr 0 Source #

Converts a variable number of arguments into curried form. Ex:

>>> :!kind '[Int,String,Double] :-> IO ()
Int -> String -> Double -> IO ()

Equations

(a ': as) :-> r = a -> as :-> r 
'[] :-> r = r 

type TypeQ = Q Type #

(!) :: WithParam p fn fn' => fn -> Param p -> fn' infixl 9 #

Supply a parameter to a function:

function ! #param_name value
function ! #x 7 ! #y 42 ! defaults

This is an infix version of with.

type (:!) (name :: Symbol) a = NamedF Identity a name #

Infix notation for the type of a named parameter.

data NamedF (f :: Type -> Type) a (name :: Symbol) where #

Assign a name to a value of type a wrapped in f.

#verbose True :: NamedF Identity Bool "verbose"

Bundled Patterns

pattern Arg :: forall a (name :: Symbol). a -> name :! a

Match on an argument without specifying its name. See also: arg.

Instances
(name ~ name', a ~ a', InjValue f) => IsLabel name (a -> NamedF f a' name') 
Instance details

Defined in Named.Internal

Methods

fromLabel :: a -> NamedF f a' name' #

arg :: Name name -> (name :! a) -> a #

arg unwraps a named parameter with the specified name. One way to use it is to match on arguments with -XViewPatterns:

fn (arg #t -> t) (arg #f -> f) = ...

This way, the names of parameters can be inferred from the patterns: no type signature for fn is required. In case a type signature for fn is provided, the parameters must come in the same order:

fn :: "t" :! Integer -> "f" :! Integer -> ...
fn (arg #t -> t) (arg #f -> f) = ... -- ok
fn (arg #f -> f) (arg #t -> t) = ... -- does not typecheck