agda2train-0.0.3.0: Agda backend to generate training data for machine learning purposes.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Output

Description

Defines the structure of the training data, as well as how to translate internal Agda definition to this format.

Synopsis

Types

type Name = String Source #

Name identifiers.

type DB = Int Source #

DeBruijn indices.

type Head = Either Name DB Source #

A head of a λ-application can either be a defined name in the global scope, or a DeBruijn index into the local context.

Generic constructions

pattern (:>) :: String -> a -> Pretty a infixr 4 Source #

data Pretty a Source #

Bundle a thing with its "pretty" version.

NB: In JSON format, we follow a shallow encoding with "pretty" being an additional field and "thing" just inlined in the top-level record.

Constructors

Pretty 

Fields

Instances

Instances details
Telescope ~> Telescope Source # 
Instance details

Defined in Output

FromJSON a => FromJSON (Pretty a) Source # 
Instance details

Defined in Output

ToJSON a => ToJSON (Pretty a) Source # 
Instance details

Defined in Output

Generic (Pretty a) Source # 
Instance details

Defined in Output

Associated Types

type Rep (Pretty a) :: Type -> Type #

Methods

from :: Pretty a -> Rep (Pretty a) x #

to :: Rep (Pretty a) x -> Pretty a #

Show a => Show (Pretty a) Source # 
Instance details

Defined in Output

Methods

showsPrec :: Int -> Pretty a -> ShowS #

show :: Pretty a -> String #

showList :: [Pretty a] -> ShowS #

type Rep (Pretty a) Source # 
Instance details

Defined in Output

type Rep (Pretty a) = D1 ('MetaData "Pretty" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "Pretty" 'PrefixI 'True) (S1 ('MetaSel ('Just "pretty") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "thing") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

data Reduced a Source #

Bundle a term with (several of) its normalised forms.

We do not repeat identical elements in subsequent evaluations (in the order simprednorm) and some fields may not be populated due to the evaluation taking to long and leading to a timeout (currently 2 seconds).

NB: Like Named, encoded in a shallow JSON.

Constructors

Reduced 

Fields

Instances

Instances details
Foldable Reduced Source # 
Instance details

Defined in Output

Methods

fold :: Monoid m => Reduced m -> m #

foldMap :: Monoid m => (a -> m) -> Reduced a -> m #

foldMap' :: Monoid m => (a -> m) -> Reduced a -> m #

foldr :: (a -> b -> b) -> b -> Reduced a -> b #

foldr' :: (a -> b -> b) -> b -> Reduced a -> b #

foldl :: (b -> a -> b) -> b -> Reduced a -> b #

foldl' :: (b -> a -> b) -> b -> Reduced a -> b #

foldr1 :: (a -> a -> a) -> Reduced a -> a #

foldl1 :: (a -> a -> a) -> Reduced a -> a #

toList :: Reduced a -> [a] #

null :: Reduced a -> Bool #

length :: Reduced a -> Int #

elem :: Eq a => a -> Reduced a -> Bool #

maximum :: Ord a => Reduced a -> a #

minimum :: Ord a => Reduced a -> a #

sum :: Num a => Reduced a -> a #

product :: Num a => Reduced a -> a #

Traversable Reduced Source # 
Instance details

Defined in Output

Methods

traverse :: Applicative f => (a -> f b) -> Reduced a -> f (Reduced b) #

sequenceA :: Applicative f => Reduced (f a) -> f (Reduced a) #

mapM :: Monad m => (a -> m b) -> Reduced a -> m (Reduced b) #

sequence :: Monad m => Reduced (m a) -> m (Reduced a) #

Functor Reduced Source # 
Instance details

Defined in Output

Methods

fmap :: (a -> b) -> Reduced a -> Reduced b #

(<$) :: a -> Reduced b -> Reduced a #

FromJSON a => FromJSON (Reduced a) Source # 
Instance details

Defined in Output

ToJSON a => ToJSON (Reduced a) Source # 
Instance details

Defined in Output

Generic (Reduced a) Source # 
Instance details

Defined in Output

Associated Types

type Rep (Reduced a) :: Type -> Type #

Methods

from :: Reduced a -> Rep (Reduced a) x #

to :: Rep (Reduced a) x -> Reduced a #

Show a => Show (Reduced a) Source # 
Instance details

Defined in Output

Methods

showsPrec :: Int -> Reduced a -> ShowS #

show :: Reduced a -> String #

showList :: [Reduced a] -> ShowS #

type Rep (Reduced a) Source # 
Instance details

Defined in Output

type Rep (Reduced a) = D1 ('MetaData "Reduced" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "Reduced" 'PrefixI 'True) ((S1 ('MetaSel ('Just "original") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "simplified") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe a))) :*: (S1 ('MetaSel ('Just "reduced") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe a)) :*: S1 ('MetaSel ('Just "normalised") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe a)))))

pattern (:~) :: Name -> a -> Named a infixr 4 Source #

data Named a Source #

Bundle a thing with its name.

NB: Like Named and Reduced, encoded in a shallow JSON.

Constructors

Named 

Fields

Instances

Instances details
Telescope ~> Telescope Source # 
Instance details

Defined in Output

FromJSON a => FromJSON (Named a) Source # 
Instance details

Defined in Output

ToJSON a => ToJSON (Named a) Source # 
Instance details

Defined in Output

Generic (Named a) Source # 
Instance details

Defined in Output

Associated Types

type Rep (Named a) :: Type -> Type #

Methods

from :: Named a -> Rep (Named a) x #

to :: Rep (Named a) x -> Named a #

Show a => Show (Named a) Source # 
Instance details

Defined in Output

Methods

showsPrec :: Int -> Named a -> ShowS #

show :: Named a -> String #

showList :: [Named a] -> ShowS #

type Rep (Named a) Source # 
Instance details

Defined in Output

type Rep (Named a) = D1 ('MetaData "Named" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "Named" 'PrefixI 'True) (S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Name) :*: S1 ('MetaSel ('Just "item") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))

Concrete types (~ JSON schema)

type FileData = Named TrainData Source #

Data for a file include the filename and its training data.

data TrainData Source #

The training data for a module, divided into three parts.

Constructors

TrainData 

Fields

  • scopeGlobal :: [ScopeEntry]

    The global scope, giving the types and definitions of all import statements.

    NB: does not contain any holes for subterms.

  • scopeLocal :: [ScopeEntry]

    The local scope, containing the types, definitions, and training data for each of this module's definitions.

  • scopePrivate :: Maybe [ScopeEntry]

    The private scope, containing private definitions not exported to the public, as well as system-generated definitions stemming from where or with.

Instances

Instances details
FromJSON TrainData Source # 
Instance details

Defined in Output

ToJSON TrainData Source # 
Instance details

Defined in Output

Generic TrainData Source # 
Instance details

Defined in Output

Associated Types

type Rep TrainData :: Type -> Type #

type Rep TrainData Source # 
Instance details

Defined in Output

type Rep TrainData = D1 ('MetaData "TrainData" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "TrainData" 'PrefixI 'True) (S1 ('MetaSel ('Just "scopeGlobal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ScopeEntry]) :*: (S1 ('MetaSel ('Just "scopeLocal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ScopeEntry]) :*: S1 ('MetaSel ('Just "scopePrivate") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [ScopeEntry])))))

data ScopeEntry' Source #

An entry in the scope: type, definitions, and holes.

Constructors

ScopeEntry 

Fields

Instances

Instances details
FromJSON ScopeEntry' Source # 
Instance details

Defined in Output

ToJSON ScopeEntry' Source # 
Instance details

Defined in Output

Generic ScopeEntry' Source # 
Instance details

Defined in Output

Associated Types

type Rep ScopeEntry' :: Type -> Type #

Show ScopeEntry' Source # 
Instance details

Defined in Output

type Rep ScopeEntry' Source # 
Instance details

Defined in Output

type Rep ScopeEntry' = D1 ('MetaData "ScopeEntry'" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "ScopeEntry" 'PrefixI 'True) (S1 ('MetaSel ('Just "_type") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Pretty (Reduced Type))) :*: (S1 ('MetaSel ('Just "definition") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Pretty Definition))) :*: S1 ('MetaSel ('Just "holes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe [Sample])))))

data Sample Source #

The training sample for each sub-hole.

Constructors

Sample 

Fields

Instances

Instances details
FromJSON Sample Source # 
Instance details

Defined in Output

ToJSON Sample Source # 
Instance details

Defined in Output

Generic Sample Source # 
Instance details

Defined in Output

Associated Types

type Rep Sample :: Type -> Type #

Methods

from :: Sample -> Rep Sample x #

to :: Rep Sample x -> Sample #

Show Sample Source # 
Instance details

Defined in Output

type Rep Sample Source # 
Instance details

Defined in Output

data Definition Source #

Agda definitions: datatypes, records, functions, postulates and primitives.

Constructors

ADT

e.g. data ℕ : Set where zero : ℕ suc : ℕ → ℕ

Fields

Constructor

e.g. `(ℕ, 0) ~ zero` or `(ℕ, 1) ~ suc`

Fields

Record

e.g. record X : Set where field x : ℕ y : ℕ

Fields

Function

e.g. f [] = [] f (x ∷ xs) = x ∷ x ∷ xs

Fields

Postulate

e.g. `postulate pred : ℕ → ℕ`

Primitive

e.g. `primitive primShowNat : ℕ → String`

Instances

Instances details
FromJSON Definition Source # 
Instance details

Defined in Output

ToJSON Definition Source # 
Instance details

Defined in Output

Generic Definition Source # 
Instance details

Defined in Output

Associated Types

type Rep Definition :: Type -> Type #

Show Definition Source # 
Instance details

Defined in Output

Definition ~> Definition Source # 
Instance details

Defined in Output

Defn ~> Definition Source # 
Instance details

Defined in Output

type Rep Definition Source # 
Instance details

Defined in Output

type Rep Definition = D1 ('MetaData "Definition" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) ((C1 ('MetaCons "ADT" 'PrefixI 'True) (S1 ('MetaSel ('Just "variants") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Type])) :+: (C1 ('MetaCons "Constructor" 'PrefixI 'True) (S1 ('MetaSel ('Just "reference") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Name) :*: S1 ('MetaSel ('Just "variant") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Integer)) :+: C1 ('MetaCons "Record" 'PrefixI 'True) (S1 ('MetaSel ('Just "telescope") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Telescope) :*: S1 ('MetaSel ('Just "fields") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Type])))) :+: (C1 ('MetaCons "Function" 'PrefixI 'True) (S1 ('MetaSel ('Just "clauses") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Clause])) :+: (C1 ('MetaCons "Postulate" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Primitive" 'PrefixI 'False) (U1 :: Type -> Type))))

data Clause Source #

Function clauses.

Constructors

Clause 

Fields

Instances

Instances details
FromJSON Clause Source # 
Instance details

Defined in Output

ToJSON Clause Source # 
Instance details

Defined in Output

Generic Clause Source # 
Instance details

Defined in Output

Associated Types

type Rep Clause :: Type -> Type #

Methods

from :: Clause -> Rep Clause x #

to :: Rep Clause x -> Clause #

Show Clause Source # 
Instance details

Defined in Output

Clause ~> Clause Source # 
Instance details

Defined in Output

type Rep Clause Source # 
Instance details

Defined in Output

type Rep Clause = D1 ('MetaData "Clause" "Output" "agda2train-0.0.3.0-inplace-agda2train-lib" 'False) (C1 ('MetaCons "Clause" 'PrefixI 'True) (S1 ('MetaSel ('Just "_telescope") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Telescope) :*: (S1 ('MetaSel ('Just "patterns") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Pattern]) :*: S1 ('MetaSel ('Just "body") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Term)))))

type Telescope = [Named (Pretty Type)] Source #

A telescope is a sequence of (named) types, a.k.a. bindings.

type Pattern = Term Source #

We under-approximate patterns as terms, e.g. losing information about forced patterns.

type Type = Term Source #

Types are the same as terms.

data Term Source #

The AST of Agda terms.

Constructors

Pi Bool (Named Term) Term

e.g. ∀ {A : Set}. A → A

Lam (Named Term)

e.g. λ x. x

App Head [Term]

e.g. f x (x + x) or @0 (λ x. x)

Lit String

e.g. 42 or "something"

Sort String

e.g. Set

Level String

e.g. 0ℓ

UnsolvedMeta

i.e. {!!}

Instances

Instances details
FromJSON Term Source # 
Instance details

Defined in Output

ToJSON Term Source # 
Instance details

Defined in Output

Generic Term Source # 
Instance details

Defined in Output

Associated Types

type Rep Term :: Type -> Type #

Methods

from :: Term -> Rep Term x #

to :: Rep Term x -> Term #

Show Term Source # 
Instance details

Defined in Output

Methods

showsPrec :: Int -> Term -> ShowS #

show :: Term -> String #

showList :: [Term] -> ShowS #

DeBruijnPattern ~> Pattern Source # 
Instance details

Defined in Output

Elim ~> Term Source # 
Instance details

Defined in Output

Telescope ~> Telescope Source # 
Instance details

Defined in Output

Term ~> Term Source # 
Instance details

Defined in Output

Type ~> Type Source # 
Instance details

Defined in Output

type Rep Term Source # 
Instance details

Defined in Output

Conversion from Agda's internal syntax

class a ~> b | a -> b where Source #

Converting between two types a and b under Agda's typechecking monad.

NB: go is only used internally to de-clutter the recursive calls.

Minimal complete definition

go

Methods

convert :: a -> TCM b Source #

go :: a -> TCM b Source #

Instances

Instances details
Clause ~> Clause Source # 
Instance details

Defined in Output

DeBruijnPattern ~> Pattern Source # 
Instance details

Defined in Output

Elim ~> Term Source # 
Instance details

Defined in Output

Telescope ~> Telescope Source # 
Instance details

Defined in Output

Term ~> Term Source # 
Instance details

Defined in Output

Type ~> Type Source # 
Instance details

Defined in Output

Definition ~> Definition Source # 
Instance details

Defined in Output

Defn ~> Definition Source # 
Instance details

Defined in Output

Utilities

pp :: Pretty a => a -> String Source #

ppm :: (MonadPretty m, PrettyTCM a) => a -> m Doc Source #

pinterleave :: (Applicative m, Semigroup (m Doc)) => m Doc -> [m Doc] -> m Doc Source #

pbindings :: (MonadPretty m, PrettyTCM a) => [(String, a)] -> [m Doc] Source #

panic :: (Pretty a, Show a) => String -> a -> b Source #

(\/) :: (a -> Bool) -> (a -> Bool) -> a -> Bool Source #

jsonOpts :: Options Source #

Configure JSON to omit empty (optional) fields and switch from camelCase to kebab-case.

Orphan instances

PrettyTCM Definition Source # 
Instance details

Methods

prettyTCM :: MonadPretty m => Definition -> m Doc #