free-foil-0.6.1: Efficient Type-Safe Capture-Avoiding Substitution for Free (Scoped Monads)
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Free.Foil.TH.MkFreeFoil

Description

Template Haskell generation for Free Foil (generic scope-safe representation of syntax).

Synopsis

Documentation

data FreeFoilConfig Source #

Config for the Template Haskell generation of data types, pattern synonyms, and conversion functions for the Free Foil representation, based on a raw recursive representation.

Since: 0.2.0

Constructors

FreeFoilConfig 

Fields

  • rawQuantifiedNames :: [Name]

    Names of raw types that may include other binders and terms as components. Some examples of syntax that might be suitable here:

    1. a type scheme in HM-style type system (to explicitly disallow nested forall)
    2. defining equation of a function (which itself is not a term)
    3. data or type synonym declaration (which itself is not a type)
    4. unification constraints (quantified or not)
  • freeFoilTermConfigs :: [FreeFoilTermConfig]

    Configurations for each term (e.g. expressions, types) group.

  • freeFoilNameModifier :: String -> String

    Name modifier for the Free Foil conterpart of a raw type name. Normally, this is just id.

  • freeFoilScopeNameModifier :: String -> String

    Name modifier for the scoped Free Foil conterpart of a raw type name. Normally, this is something like (Scoped ++).

  • signatureNameModifier :: String -> String

    Name modifier for the signature conterpart of a raw type name or raw constructor name. Normally, this is something like (++ Sig).

  • freeFoilConNameModifier :: String -> String

    Name modifier for the Free Foil conterpart (pattern synonym) of a raw constructor name. Normally, this is just id.

  • freeFoilConvertToName :: String -> String

    Name of a conversion function (from raw to scope-safe) for a raw type name. Normally, this is something like ("to" ++).

  • freeFoilConvertFromName :: String -> String

    Name of a conversion function (from scope-safe to raw) for a raw type name. Normally, this is something like ("from" ++).

data FreeFoilTermConfig Source #

Config for a single term group, for the Template Haskell generation of data types, pattern synonyms, and conversion functions for the Free Foil representation, based on a raw recursive representation.

Since: 0.2.0

Constructors

FreeFoilTermConfig 

Fields

  • rawIdentName :: Name

    The type name for the identifiers. When identifiers occur in a term, they are converted to Name (with an appropriate type-level scope parameter). When identifiers occur in a pattern, they are converted to NameBinder (with appropriate type-level scope parameters).

  • rawTermName :: Name

    The type name for the term. This will be the main recursive type to be converted into an AST.

  • rawBindingName :: Name

    The type name for the binders (patterns). This will be the main binder type to used in AST-representation of the terms.

  • rawScopeName :: Name

    The type name for the scoped term. This will be replaced with either ScopedAST (with outer scope) or AST (with inner scope) depending on its occurrence in a regular (sub)term or some quantified syntax.

  • rawVarConName :: Name

    The constructor name for the variables in a term. This constructor will be replaced with the standard Var. It is expected to have exactly one field of type rawIdentName.

  • rawSubTermNames :: [Name]

    Type names for subterm syntax. This will rely on the main term type (rawTermName) for recursive occurrences. Template Haskell will also generate signatures for these.

  • rawSubScopeNames :: [Name]

    Type names for scoped subterm syntax. This will rely on the main term type (rawTermName) for recursive occurrences. Template Haskell will also generate signatures for these.

  • intToRawIdentName :: Name

    Name of a function that converts Int to a raw identifier. Normally, this is something like (i -> VarIdent ("x" ++ show i)). This is required to generate standard conversions from scope-safe to raw representation.

  • rawVarIdentToTermName :: Name

    Name of a function that converts a raw identifier into a raw term. Normally, this is some kind of Var or TypeVar data constructor. This is required to generate standard conversions from scope-safe to raw representation.

  • rawTermToScopeName :: Name

    Name of a function that converts a raw term into a raw scoped term. Normally, this is some kind of ScopedTerm or ScopedType data constructor.

  • rawScopeToTermName :: Name

    Name of a function that extracts a raw term from a raw scoped term. Normally, this is something like ((ScopedTerm term) -> term).

data FreeFoilOptions Source #

Options of mkFreeFoilWith.

Since: 0.6.0

Constructors

FreeFoilOptions 

Fields

  • signatureInstances :: [Name]

    The classes whose instances every generated signature gets. Bifunctor, Bifoldable, Bitraversable and NFData come with INLINE pragmas on the methods, and ZipMatchK and ZipMatchFoldK are written out as Data.ZipMatchK.TH derives them. All six are generated by default, since GHC does not inline the derived methods of a signature with about ten constructors or more, and every generic traversal of the syntax goes through them. Leave out the instances you write or derive yourself. With [], none is generated. Any other class name is rejected by the splice, and so is Bitraversable without its superclasses. The instances of the payload types, such as identifiers and positions, must be declared before the splice, since a later declaration group is not visible to it.

  • patternInstances :: [Name]

    The classes whose instances every generated binding type gets: NFData by default, written out. A binding type is a GADT whenever a constructor binds two names, which rules out the Generic default. The same rules as for signatureInstances apply.

defaultFreeFoilOptions :: FreeFoilOptions Source #

The default options. Every instance is generated.

Since: 0.6.0

mkFreeFoil :: FreeFoilConfig -> Q [Dec] Source #

Generate scope-safe types and pattern synonyms for a given raw set of types:

  1. Scope-safe quantified types (e.g. type schemas, defining equations of functions, unification constraints, data/type declarations)
  2. Scope-safe terms, scoped terms, subterms, scoped subterms.
  3. Scope-safe patterns.
  4. Signatures for terms, subterms, and scoped subterms.
  5. Pattern synonyms for terms, subterms, and scoped subterms.

A scope-safe pattern type is a newtype when its raw type has exactly one constructor with exactly one field, and that field is an identifier or a nested pattern (e.g. newtype Pattern = PatternVar VarIdent). Such a pattern has the runtime representation of the field it wraps. Otherwise the pattern type is data.

Signatures are generated together with instances of Bitraversable, ZipMatchK and ZipMatchFoldK. Use mkFreeFoilWith to control which instances are generated.

Since: 0.2.0

mkFreeFoilWith :: FreeFoilOptions -> FreeFoilConfig -> Q [Dec] Source #

mkFreeFoil with options.

Since: 0.6.0

mkFreeFoilConversions :: FreeFoilConfig -> Q [Dec] Source #

Generate conversions to and from scope-safe representation:

  1. Conversions for scope-safe quantified types (e.g. type schemas, defining equations of functions, unification constraints, data/type declarations)
  2. Conversions for scope-safe terms, scoped terms, subterms, scoped subterms.
  3. CPS-style conversions for scope-safe patterns.
  4. Helpers for signatures of terms, subterms, and scoped subterms.

Since: 0.2.0