core

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package core contains the core Dhall language implementation.

If you have a Term, you can call TypeOf() to ensure it is well-typed and to get its type. A well-typed Term can be Eval()ed to return a Value. A Value represents a fully beta-normalized Dhall value. If you have a Value, you can use Quote() to express it as a Term.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlphaEquivalent

func AlphaEquivalent(v1 Value, v2 Value) bool

AlphaEquivalent reports if two Values are equal after alpha-normalization, as defined by the standard. Broadly, two values are alpha-equivalent if they are structurally identical, ignoring label names.

func Quote

func Quote(v Value) term.Term

Quote takes the Value v and turns it back into a Term.

Types

type BoolLit

type BoolLit bool

A BoolLit is a Value representing a Dhall boolean literal.

const (
	True  BoolLit = true
	False BoolLit = false
)

Naturally, it is True or False.

type Builtin

type Builtin string

A Builtin is a Value representing one of Dhall's non-Callable builtin constants.

const (
	Double  Builtin = "Double"
	Text    Builtin = "Text"
	Bool    Builtin = "Bool"
	Natural Builtin = "Natural"
	Integer Builtin = "Integer"
)

These are the Builtins.

type Callable

type Callable interface {
	Value
	Call(Value) Value
	ArgType() Value
}

Callable is a function Value that can be called with one Value argument. Call() may return nil if normalization isn't possible (for example, `Natural/even x` does not normalize). ArgType() returns the declared type of Call()'s parameter.

var (
	NaturalBuild     Callable = naturalBuild{}
	NaturalEven      Callable = naturalEven{}
	NaturalFold      Callable = naturalFold{}
	NaturalIsZero    Callable = naturalIsZero{}
	NaturalOdd       Callable = naturalOdd{}
	NaturalShow      Callable = naturalShow{}
	NaturalSubtract  Callable = naturalSubtract{}
	NaturalToInteger Callable = naturalToInteger{}
	IntegerClamp     Callable = integerClamp{}
	IntegerNegate    Callable = integerNegate{}
	IntegerShow      Callable = integerShow{}
	IntegerToDouble  Callable = integerToDouble{}
	DoubleShow       Callable = doubleShow{}

	Optional      Callable = optional{}
	OptionalBuild Callable = optionalBuild{}
	OptionalFold  Callable = optionalFold{}
	None          Callable = none{}

	TextShow Callable = textShow{}

	List        Callable = list{}
	ListBuild   Callable = listBuild{}
	ListFold    Callable = listFold{}
	ListLength  Callable = listLength{}
	ListHead    Callable = listHead{}
	ListLast    Callable = listLast{}
	ListIndexed Callable = listIndexed{}
	ListReverse Callable = listReverse{}
)

These are the builtin Callable Values.

type DoubleLit

type DoubleLit float64

A DoubleLit is a literal Value of type Double.

func (DoubleLit) String

func (d DoubleLit) String() string

type EmptyList

type EmptyList struct{ Type Value }

An EmptyList is an empty list literal Value of the given type.

type GomegaMatcher

type GomegaMatcher interface {
	Match(actual interface{}) (success bool, err error)
	FailureMessage(actual interface{}) (message string)
	NegatedFailureMessage(actual interface{}) (message string)
}

GomegaMatcher is a copy of github.com/onsi/gomega/types.GomegaMatcher, to avoid a dependency on gomega for users who don't want it.

func BeAlphaEquivalentTo

func BeAlphaEquivalentTo(expected interface{}) GomegaMatcher

BeAlphaEquivalentTo returns a Gomega matcher which checks that a Term or Value is equivalent to the expected Term or Value. If either the expected or actual is a Term, it is Eval()ed first; then the Values are compared with AlphaEquivalentVals().

type IntegerLit

type IntegerLit int

An IntegerLit is a literal Value of type Integer.

type ListOf

type ListOf struct{ Type Value }

ListOf is a Value representing `List a`

type NaturalLit

type NaturalLit uint

A NaturalLit is a literal Value of type Natural.

type NonEmptyList

type NonEmptyList []Value

A NonEmptyList is a non-empty list literal Value with the given contents.

type NoneOf

type NoneOf struct{ Type Value }

NoneOf is a Value representing `None a`

type OptionalOf

type OptionalOf struct{ Type Value }

OptionalOf is a Value representing `Optional a`

type Pi

type Pi struct {
	Label    string
	Domain   Value
	Codomain func(Value) Value
}

A Pi is a Value representing a Dhall Pi type. Domain is the type of the domain, and Codomain is a go function which returns the type of the codomain, given the value of the domain.

func NewFnType

func NewFnType(label string, domain Value, codomain Value) Pi

NewFnType returns a non-dependent function type Value.

func NewPi

func NewPi(label string, domain Value, codomain func(Value) Value) Pi

NewPi returns a new pi Value.

type PlainTextLit

type PlainTextLit string

A PlainTextLit is a literal Value of type Text, containing no interpolations.

type RecordLit

type RecordLit map[string]Value

A RecordLit is a Value representing a Dhall record literal.

type RecordType

type RecordType map[string]Value

A RecordType is a Value representing a Dhall record type.

type Some

type Some struct{ Val Value }

Some represents a Value which is present in an Optional type.

type UnionType

type UnionType map[string]Value

A UnionType is a Value representing a Dhall union type.

type Universe

type Universe int

A Universe is a Value representing a type of types.

const (
	Type Universe = iota
	Kind
	Sort
)

These are the valid Universes.

type Value

type Value interface {
	// contains filtered or unexported methods
}

A Value is a Dhall value in beta-normal form. You can think of Values as the subset of Dhall which cannot be beta-reduced any further. Valid Values include 3, "foo" and λ(x : Natural) → x.

You create a Value by calling Eval() on a Term. You can convert a Value back to a Term with Quote().

func AlphaBetaEval

func AlphaBetaEval(t term.Term) Value

AlphaBetaEval alpha-beta-normalizes Term to a Value.

func Eval

func Eval(t term.Term) Value

Eval normalizes Term to a Value.

func TypeOf

func TypeOf(t term.Term) (Value, error)

TypeOf typechecks a Term, returning the type in normal form. If typechecking fails, an error is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL