Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the core calculus for the Dhall language.
Dhall is essentially a fork of the morte
compiler but with more built-in
functionality, better error messages, and Haskell integration
Synopsis
- data Const
- newtype Directory = Directory {
- components :: [Text]
- data File = File {}
- data FilePrefix
- data Import = Import {}
- data ImportHashed = ImportHashed {}
- data ImportMode
- data ImportType
- data URL = URL {}
- data Scheme
- newtype DhallDouble = DhallDouble {}
- data Var = V Text !Int
- data Binding s a = Binding {
- bindingSrc0 :: Maybe s
- variable :: Text
- bindingSrc1 :: Maybe s
- annotation :: Maybe (Maybe s, Expr s a)
- bindingSrc2 :: Maybe s
- value :: Expr s a
- makeBinding :: Text -> Expr s a -> Binding s a
- data Chunks s a = Chunks [(Text, Expr s a)] Text
- data PreferAnnotation s a
- data RecordField s a = RecordField {
- recordFieldSrc0 :: Maybe s
- recordFieldValue :: Expr s a
- recordFieldSrc1 :: Maybe s
- recordFieldSrc2 :: Maybe s
- makeRecordField :: Expr s a -> RecordField s a
- data FunctionBinding s a = FunctionBinding {}
- makeFunctionBinding :: Text -> Expr s a -> FunctionBinding s a
- data FieldSelection s = FieldSelection {}
- makeFieldSelection :: Text -> FieldSelection s
- data WithComponent
- data Expr s a
- = Const Const
- | Var Var
- | Lam (Maybe CharacterSet) (FunctionBinding s a) (Expr s a)
- | Pi (Maybe CharacterSet) Text (Expr s a) (Expr s a)
- | App (Expr s a) (Expr s a)
- | Let (Binding s a) (Expr s a)
- | Annot (Expr s a) (Expr s a)
- | Bool
- | BoolLit Bool
- | BoolAnd (Expr s a) (Expr s a)
- | BoolOr (Expr s a) (Expr s a)
- | BoolEQ (Expr s a) (Expr s a)
- | BoolNE (Expr s a) (Expr s a)
- | BoolIf (Expr s a) (Expr s a) (Expr s a)
- | Natural
- | NaturalLit Natural
- | NaturalFold
- | NaturalBuild
- | NaturalIsZero
- | NaturalEven
- | NaturalOdd
- | NaturalToInteger
- | NaturalShow
- | NaturalSubtract
- | NaturalPlus (Expr s a) (Expr s a)
- | NaturalTimes (Expr s a) (Expr s a)
- | Integer
- | IntegerLit Integer
- | IntegerClamp
- | IntegerNegate
- | IntegerShow
- | IntegerToDouble
- | Double
- | DoubleLit DhallDouble
- | DoubleShow
- | Text
- | TextLit (Chunks s a)
- | TextAppend (Expr s a) (Expr s a)
- | TextReplace
- | TextShow
- | Date
- | DateLiteral Day
- | Time
- | TimeLiteral TimeOfDay Word
- | TimeZone
- | TimeZoneLiteral TimeZone
- | List
- | ListLit (Maybe (Expr s a)) (Seq (Expr s a))
- | ListAppend (Expr s a) (Expr s a)
- | ListBuild
- | ListFold
- | ListLength
- | ListHead
- | ListLast
- | ListIndexed
- | ListReverse
- | Optional
- | Some (Expr s a)
- | None
- | Record (Map Text (RecordField s a))
- | RecordLit (Map Text (RecordField s a))
- | Union (Map Text (Maybe (Expr s a)))
- | Combine (Maybe CharacterSet) (Maybe Text) (Expr s a) (Expr s a)
- | CombineTypes (Maybe CharacterSet) (Expr s a) (Expr s a)
- | Prefer (Maybe CharacterSet) (PreferAnnotation s a) (Expr s a) (Expr s a)
- | RecordCompletion (Expr s a) (Expr s a)
- | Merge (Expr s a) (Expr s a) (Maybe (Expr s a))
- | ToMap (Expr s a) (Maybe (Expr s a))
- | ShowConstructor (Expr s a)
- | Field (Expr s a) (FieldSelection s)
- | Project (Expr s a) (Either [Text] (Expr s a))
- | Assert (Expr s a)
- | Equivalent (Maybe CharacterSet) (Expr s a) (Expr s a)
- | With (Expr s a) (NonEmpty WithComponent) (Expr s a)
- | Note s (Expr s a)
- | ImportAlt (Expr s a) (Expr s a)
- | Embed a
- alphaNormalize :: Expr s a -> Expr s a
- normalize :: Eq a => Expr s a -> Expr t a
- normalizeWith :: Eq a => Maybe (ReifiedNormalizer a) -> Expr s a -> Expr t a
- normalizeWithM :: (Monad m, Eq a) => NormalizerM m a -> Expr s a -> m (Expr t a)
- type Normalizer a = NormalizerM Identity a
- type NormalizerM m a = forall s. Expr s a -> m (Maybe (Expr s a))
- newtype ReifiedNormalizer a = ReifiedNormalizer {}
- judgmentallyEqual :: Eq a => Expr s a -> Expr t a -> Bool
- subst :: Var -> Expr s a -> Expr s a -> Expr s a
- shift :: Int -> Var -> Expr s a -> Expr s a
- isNormalized :: Eq a => Expr s a -> Bool
- isNormalizedWith :: (Eq s, Eq a) => Normalizer a -> Expr s a -> Bool
- denote :: Expr s a -> Expr t a
- renote :: Expr Void a -> Expr s a
- shallowDenote :: Expr s a -> Expr s a
- freeIn :: Eq a => Var -> Expr s a -> Bool
- pretty :: Pretty a => a -> Text
- subExpressions :: Applicative f => (Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a)
- subExpressionsWith :: Applicative f => (a -> f (Expr s b)) -> (Expr s a -> f (Expr s b)) -> Expr s a -> f (Expr s b)
- chunkExprs :: Applicative f => (Expr s a -> f (Expr t b)) -> Chunks s a -> f (Chunks t b)
- bindingExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> Binding s a -> f (Binding s b)
- recordFieldExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> RecordField s a -> f (RecordField s b)
- functionBindingExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> FunctionBinding s a -> f (FunctionBinding s b)
- multiLet :: Binding s a -> Expr s a -> MultiLet s a
- wrapInLets :: Foldable f => f (Binding s a) -> Expr s a -> Expr s a
- data MultiLet s a = MultiLet (NonEmpty (Binding s a)) (Expr s a)
- internalError :: Text -> forall b. b
- reservedIdentifiers :: HashSet Text
- escapeText :: Text -> Text
- pathCharacter :: Char -> Bool
- throws :: (Exception e, MonadIO io) => Either e a -> io a
- textShow :: Text -> Text
- censorExpression :: Expr Src a -> Expr Src a
- censorText :: Text -> Text
Syntax
Constants for a pure type system
The axioms are:
⊦ Type : Kind ⊦ Kind : Sort
... and the valid rule pairs are:
⊦ Type ↝ Type : Type -- Functions from terms to terms (ordinary functions) ⊦ Kind ↝ Type : Type -- Functions from types to terms (type-polymorphic functions) ⊦ Sort ↝ Type : Type -- Functions from kinds to terms ⊦ Kind ↝ Kind : Kind -- Functions from types to types (type-level functions) ⊦ Sort ↝ Kind : Sort -- Functions from kinds to types (kind-polymorphic functions) ⊦ Sort ↝ Sort : Sort -- Functions from kinds to kinds (kind-level functions)
Note that Dhall does not support functions from terms to types and therefore Dhall is not a dependently typed language
Instances
Bounded Const Source # | |
Enum Const Source # | |
Eq Const Source # | |
Data Const Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Const -> c Const # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Const # dataTypeOf :: Const -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Const) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const) # gmapT :: (forall b. Data b => b -> b) -> Const -> Const # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r # gmapQ :: (forall d. Data d => d -> u) -> Const -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Const -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Const -> m Const # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Const -> m Const # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Const -> m Const # | |
Ord Const Source # | |
Show Const Source # | |
Generic Const Source # | |
NFData Const Source # | |
Defined in Dhall.Syntax | |
Pretty Const Source # | |
Defined in Dhall.Syntax | |
Lift Const Source # | |
type Rep Const Source # | |
Defined in Dhall.Syntax |
Internal representation of a directory that stores the path components in reverse order
In other words, the directory /foo/bar/baz
is encoded as
Directory { components = [ "baz", "bar", "foo" ] }
Directory | |
|
Instances
Eq Directory Source # | |
Ord Directory Source # | |
Defined in Dhall.Syntax | |
Show Directory Source # | |
Generic Directory Source # | |
Semigroup Directory Source # | |
NFData Directory Source # | |
Defined in Dhall.Syntax | |
Pretty Directory Source # | |
Defined in Dhall.Syntax | |
type Rep Directory Source # | |
Defined in Dhall.Syntax |
Instances
Eq File Source # | |
Ord File Source # | |
Show File Source # | |
Generic File Source # | |
Semigroup File Source # | |
NFData File Source # | |
Defined in Dhall.Syntax | |
Pretty File Source # | |
Defined in Dhall.Syntax | |
type Rep File Source # | |
Defined in Dhall.Syntax type Rep File = D1 ('MetaData "File" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "File" 'PrefixI 'True) (S1 ('MetaSel ('Just "directory") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Directory) :*: S1 ('MetaSel ('Just "file") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) |
data FilePrefix Source #
The beginning of a file path which anchors subsequent path components
Instances
Reference to an external resource
Instances
Eq Import Source # | |
Ord Import Source # | |
Show Import Source # | |
Generic Import Source # | |
Semigroup Import Source # | |
NFData Import Source # | |
Defined in Dhall.Syntax | |
Pretty Import Source # | |
Defined in Dhall.Syntax | |
Serialise (Expr Void Import) Source # | |
type Rep Import Source # | |
Defined in Dhall.Syntax type Rep Import = D1 ('MetaData "Import" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "Import" 'PrefixI 'True) (S1 ('MetaSel ('Just "importHashed") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ImportHashed) :*: S1 ('MetaSel ('Just "importMode") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ImportMode))) |
data ImportHashed Source #
A ImportType
extended with an optional hash for semantic integrity checks
Instances
data ImportMode Source #
How to interpret the import's contents (i.e. as Dhall code or raw text)
Instances
data ImportType Source #
The type of import (i.e. local vs. remote vs. environment)
Local FilePrefix File | Local path |
Remote URL | URL of remote resource and optional headers stored in an import |
Env Text | Environment variable |
Missing |
Instances
This type stores all of the components of a remote import
Instances
Eq URL Source # | |
Ord URL Source # | |
Show URL Source # | |
Generic URL Source # | |
NFData URL Source # | |
Defined in Dhall.Syntax | |
Pretty URL Source # | |
Defined in Dhall.Syntax | |
type Rep URL Source # | |
Defined in Dhall.Syntax type Rep URL = D1 ('MetaData "URL" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "URL" 'PrefixI 'True) ((S1 ('MetaSel ('Just "scheme") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Scheme) :*: S1 ('MetaSel ('Just "authority") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :*: (S1 ('MetaSel ('Just "path") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 File) :*: (S1 ('MetaSel ('Just "query") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "headers") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Expr Src Import))))))) |
The URI scheme
newtype DhallDouble Source #
This wrapper around Double
exists for its Eq
instance which is
defined via the binary encoding of Dhall Double
s.
Instances
Eq DhallDouble Source # | This instance satisfies all the customary In particular:
This instance is also consistent with with the binary encoding of Dhall
\a b -> (a == b) == (toBytes a == toBytes b) |
Defined in Dhall.Syntax (==) :: DhallDouble -> DhallDouble -> Bool # (/=) :: DhallDouble -> DhallDouble -> Bool # | |
Data DhallDouble Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DhallDouble -> c DhallDouble # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DhallDouble # toConstr :: DhallDouble -> Constr # dataTypeOf :: DhallDouble -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c DhallDouble) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DhallDouble) # gmapT :: (forall b. Data b => b -> b) -> DhallDouble -> DhallDouble # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DhallDouble -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DhallDouble -> r # gmapQ :: (forall d. Data d => d -> u) -> DhallDouble -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> DhallDouble -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble # | |
Ord DhallDouble Source # | This instance relies on the |
Defined in Dhall.Syntax compare :: DhallDouble -> DhallDouble -> Ordering # (<) :: DhallDouble -> DhallDouble -> Bool # (<=) :: DhallDouble -> DhallDouble -> Bool # (>) :: DhallDouble -> DhallDouble -> Bool # (>=) :: DhallDouble -> DhallDouble -> Bool # max :: DhallDouble -> DhallDouble -> DhallDouble # min :: DhallDouble -> DhallDouble -> DhallDouble # | |
Show DhallDouble Source # | |
Defined in Dhall.Syntax showsPrec :: Int -> DhallDouble -> ShowS # show :: DhallDouble -> String # showList :: [DhallDouble] -> ShowS # | |
Generic DhallDouble Source # | |
Defined in Dhall.Syntax type Rep DhallDouble :: Type -> Type # from :: DhallDouble -> Rep DhallDouble x # to :: Rep DhallDouble x -> DhallDouble # | |
NFData DhallDouble Source # | |
Defined in Dhall.Syntax rnf :: DhallDouble -> () # | |
Lift DhallDouble Source # | |
Defined in Dhall.Syntax lift :: DhallDouble -> Q Exp # liftTyped :: DhallDouble -> Q (TExp DhallDouble) # | |
type Rep DhallDouble Source # | |
Defined in Dhall.Syntax type Rep DhallDouble = D1 ('MetaData "DhallDouble" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'True) (C1 ('MetaCons "DhallDouble" 'PrefixI 'True) (S1 ('MetaSel ('Just "getDhallDouble") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Double))) |
Label for a bound variable
The Text
field is the variable's name (i.e. "x
").
The Int
field disambiguates variables with the same name if there are
multiple bound variables of the same name in scope. Zero refers to the
nearest bound variable and the index increases by one for each bound
variable of the same name going outward. The following diagram may help:
┌──refers to──┐ │ │ v │ λ(x : Type) → λ(y : Type) → λ(x : Type) → x@0 ┌─────────────────refers to─────────────────┐ │ │ v │ λ(x : Type) → λ(y : Type) → λ(x : Type) → x@1
This Int
behaves like a De Bruijn index in the special case where all
variables have the same name.
You can optionally omit the index if it is 0
:
┌─refers to─┐ │ │ v │ λ(x : Type) → λ(y : Type) → λ(x : Type) → x
Zero indices are omitted when pretty-printing Var
s and non-zero indices
appear as a numeric suffix.
Instances
Eq Var Source # | |
Data Var Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Var -> c Var # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Var # dataTypeOf :: Var -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Var) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var) # gmapT :: (forall b. Data b => b -> b) -> Var -> Var # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r # gmapQ :: (forall d. Data d => d -> u) -> Var -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Var -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Var -> m Var # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var # | |
Ord Var Source # | |
Show Var Source # | |
IsString Var Source # | |
Defined in Dhall.Syntax fromString :: String -> Var # | |
Generic Var Source # | |
NFData Var Source # | |
Defined in Dhall.Syntax | |
Pretty Var Source # | |
Defined in Dhall.Syntax | |
Lift Var Source # | |
type Rep Var Source # | |
Defined in Dhall.Syntax type Rep Var = D1 ('MetaData "Var" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "V" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))) |
Record the binding part of a let
expression.
For example,
let {- A -} x {- B -} : {- C -} Bool = {- D -} True in x
… will be instantiated as follows:
bindingSrc0
corresponds to theA
comment.variable
is"x"
bindingSrc1
corresponds to theB
comment.annotation
isJust
a pair, corresponding to theC
comment andBool
.bindingSrc2
corresponds to theD
comment.value
corresponds toTrue
.
Binding | |
|
Instances
Bifunctor Binding Source # | |
(Lift s, Lift a) => Lift (Binding s a :: Type) Source # | |
Functor (Binding s) Source # | |
Foldable (Binding s) Source # | |
Defined in Dhall.Syntax fold :: Monoid m => Binding s m -> m # foldMap :: Monoid m => (a -> m) -> Binding s a -> m # foldMap' :: Monoid m => (a -> m) -> Binding s a -> m # foldr :: (a -> b -> b) -> b -> Binding s a -> b # foldr' :: (a -> b -> b) -> b -> Binding s a -> b # foldl :: (b -> a -> b) -> b -> Binding s a -> b # foldl' :: (b -> a -> b) -> b -> Binding s a -> b # foldr1 :: (a -> a -> a) -> Binding s a -> a # foldl1 :: (a -> a -> a) -> Binding s a -> a # toList :: Binding s a -> [a] # length :: Binding s a -> Int # elem :: Eq a => a -> Binding s a -> Bool # maximum :: Ord a => Binding s a -> a # minimum :: Ord a => Binding s a -> a # | |
Traversable (Binding s) Source # | |
(Eq s, Eq a) => Eq (Binding s a) Source # | |
(Data s, Data a) => Data (Binding s a) Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Binding s a -> c (Binding s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Binding s a) # toConstr :: Binding s a -> Constr # dataTypeOf :: Binding s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Binding s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Binding s a)) # gmapT :: (forall b. Data b => b -> b) -> Binding s a -> Binding s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Binding s a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Binding s a -> r # gmapQ :: (forall d. Data d => d -> u) -> Binding s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Binding s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a) # | |
(Ord s, Ord a) => Ord (Binding s a) Source # | |
(Show s, Show a) => Show (Binding s a) Source # | |
Generic (Binding s a) Source # | |
(NFData s, NFData a) => NFData (Binding s a) Source # | |
Defined in Dhall.Syntax | |
type Rep (Binding s a) Source # | |
Defined in Dhall.Syntax type Rep (Binding s a) = D1 ('MetaData "Binding" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "Binding" 'PrefixI 'True) ((S1 ('MetaSel ('Just "bindingSrc0") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s)) :*: (S1 ('MetaSel ('Just "variable") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "bindingSrc1") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s)))) :*: (S1 ('MetaSel ('Just "annotation") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe (Maybe s, Expr s a))) :*: (S1 ('MetaSel ('Just "bindingSrc2") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s)) :*: S1 ('MetaSel ('Just "value") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Expr s a)))))) |
makeBinding :: Text -> Expr s a -> Binding s a Source #
Construct a Binding
with no source information and no type annotation.
The body of an interpolated Text
literal
Instances
(Lift s, Lift a) => Lift (Chunks s a :: Type) Source # | |
Functor (Chunks s) Source # | |
Foldable (Chunks s) Source # | |
Defined in Dhall.Syntax fold :: Monoid m => Chunks s m -> m # foldMap :: Monoid m => (a -> m) -> Chunks s a -> m # foldMap' :: Monoid m => (a -> m) -> Chunks s a -> m # foldr :: (a -> b -> b) -> b -> Chunks s a -> b # foldr' :: (a -> b -> b) -> b -> Chunks s a -> b # foldl :: (b -> a -> b) -> b -> Chunks s a -> b # foldl' :: (b -> a -> b) -> b -> Chunks s a -> b # foldr1 :: (a -> a -> a) -> Chunks s a -> a # foldl1 :: (a -> a -> a) -> Chunks s a -> a # elem :: Eq a => a -> Chunks s a -> Bool # maximum :: Ord a => Chunks s a -> a # minimum :: Ord a => Chunks s a -> a # | |
Traversable (Chunks s) Source # | |
(Eq s, Eq a) => Eq (Chunks s a) Source # | |
(Data s, Data a) => Data (Chunks s a) Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Chunks s a) # toConstr :: Chunks s a -> Constr # dataTypeOf :: Chunks s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Chunks s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Chunks s a)) # gmapT :: (forall b. Data b => b -> b) -> Chunks s a -> Chunks s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Chunks s a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Chunks s a -> r # gmapQ :: (forall d. Data d => d -> u) -> Chunks s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Chunks s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a) # | |
(Ord s, Ord a) => Ord (Chunks s a) Source # | |
(Show s, Show a) => Show (Chunks s a) Source # | |
IsString (Chunks s a) Source # | |
Defined in Dhall.Syntax fromString :: String -> Chunks s a # | |
Generic (Chunks s a) Source # | |
Semigroup (Chunks s a) Source # | |
Monoid (Chunks s a) Source # | |
(NFData s, NFData a) => NFData (Chunks s a) Source # | |
Defined in Dhall.Syntax | |
type Rep (Chunks s a) Source # | |
Defined in Dhall.Syntax type Rep (Chunks s a) = D1 ('MetaData "Chunks" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "Chunks" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Text, Expr s a)]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) |
data PreferAnnotation s a Source #
Used to record the origin of a //
operator (i.e. from source code or a
product of desugaring)
PreferFromSource | |
PreferFromWith (Expr s a) | Stores the original |
PreferFromCompletion |
Instances
data RecordField s a Source #
Record the field of a record-type and record-literal expression. The reason why we use the same ADT for both of them is because they store the same information.
For example,
{ {- A -} x {- B -} : {- C -} T }
... or
{ {- A -} x {- B -} = {- C -} T }
will be instantiated as follows:
recordFieldSrc0
corresponds to theA
comment.recordFieldValue
isT
recordFieldSrc1
corresponds to theB
comment.recordFieldSrc2
corresponds to theC
comment.
Although the A
comment isn't annotating the T
Record Field,
this is the best place to keep these comments.
Note that recordFieldSrc2
is always Nothing
when the RecordField
is for
a punned entry, because there is no =
sign. For example,
{ {- A -} x {- B -} }
will be instantiated as follows:
recordFieldSrc0
corresponds to theA
comment.recordFieldValue
corresponds to(Var "x")
recordFieldSrc1
corresponds to theB
comment.recordFieldSrc2
will beNothing
The labels involved in a record using dot-syntax like in this example:
{ {- A -} a {- B -} . {- C -} b {- D -} . {- E -} c {- F -} = {- G -} e }
will be instantiated as follows:
- For both the
a
andb
field,recordfieldSrc2
isNothing
- For the
a
field: recordFieldSrc0
corresponds to theA
commentrecordFieldSrc1
corresponds to theB
comment- For the
b
field: recordFieldSrc0
corresponds to theC
commentrecordFieldSrc1
corresponds to theD
comment- For the
c
field: recordFieldSrc0
corresponds to theE
commentrecordFieldSrc1
corresponds to theF
commentrecordFieldSrc2
corresponds to theG
comment
That is, for every label except the last one the semantics of
recordFieldSrc0
and recordFieldSrc1
are the same from a regular record
label but recordFieldSrc2
is always Nothing
. For the last keyword, all
srcs are Just
RecordField | |
|
Instances
Bifunctor RecordField Source # | |
Defined in Dhall.Syntax bimap :: (a -> b) -> (c -> d) -> RecordField a c -> RecordField b d # first :: (a -> b) -> RecordField a c -> RecordField b c # second :: (b -> c) -> RecordField a b -> RecordField a c # | |
(Lift s, Lift a) => Lift (RecordField s a :: Type) Source # | |
Defined in Dhall.Syntax lift :: RecordField s a -> Q Exp # liftTyped :: RecordField s a -> Q (TExp (RecordField s a)) # | |
Functor (RecordField s) Source # | |
Defined in Dhall.Syntax fmap :: (a -> b) -> RecordField s a -> RecordField s b # (<$) :: a -> RecordField s b -> RecordField s a # | |
Foldable (RecordField s) Source # | |
Defined in Dhall.Syntax fold :: Monoid m => RecordField s m -> m # foldMap :: Monoid m => (a -> m) -> RecordField s a -> m # foldMap' :: Monoid m => (a -> m) -> RecordField s a -> m # foldr :: (a -> b -> b) -> b -> RecordField s a -> b # foldr' :: (a -> b -> b) -> b -> RecordField s a -> b # foldl :: (b -> a -> b) -> b -> RecordField s a -> b # foldl' :: (b -> a -> b) -> b -> RecordField s a -> b # foldr1 :: (a -> a -> a) -> RecordField s a -> a # foldl1 :: (a -> a -> a) -> RecordField s a -> a # toList :: RecordField s a -> [a] # null :: RecordField s a -> Bool # length :: RecordField s a -> Int # elem :: Eq a => a -> RecordField s a -> Bool # maximum :: Ord a => RecordField s a -> a # minimum :: Ord a => RecordField s a -> a # sum :: Num a => RecordField s a -> a # product :: Num a => RecordField s a -> a # | |
Traversable (RecordField s) Source # | |
Defined in Dhall.Syntax traverse :: Applicative f => (a -> f b) -> RecordField s a -> f (RecordField s b) # sequenceA :: Applicative f => RecordField s (f a) -> f (RecordField s a) # mapM :: Monad m => (a -> m b) -> RecordField s a -> m (RecordField s b) # sequence :: Monad m => RecordField s (m a) -> m (RecordField s a) # | |
(Eq s, Eq a) => Eq (RecordField s a) Source # | |
Defined in Dhall.Syntax (==) :: RecordField s a -> RecordField s a -> Bool # (/=) :: RecordField s a -> RecordField s a -> Bool # | |
(Data s, Data a) => Data (RecordField s a) Source # | |
Defined in Dhall.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RecordField s a -> c (RecordField s a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (RecordField s a) # toConstr :: RecordField s a -> Constr # dataTypeOf :: RecordField s a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (RecordField s a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (RecordField s a)) # gmapT :: (forall b. Data b => b -> b) -> RecordField s a -> RecordField s a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RecordField s a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RecordField s a -> r # gmapQ :: (forall d. Data d => d -> u) -> RecordField s a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> RecordField s a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> RecordField s a -> m (RecordField s a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RecordField s a -> m (RecordField s a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RecordField s a -> m (RecordField s a) # | |
(Ord s, Ord a) => Ord (RecordField s a) Source # | |
Defined in Dhall.Syntax compare :: RecordField s a -> RecordField s a -> Ordering # (<) :: RecordField s a -> RecordField s a -> Bool # (<=) :: RecordField s a -> RecordField s a -> Bool # (>) :: RecordField s a -> RecordField s a -> Bool # (>=) :: RecordField s a -> RecordField s a -> Bool # max :: RecordField s a -> RecordField s a -> RecordField s a # min :: RecordField s a -> RecordField s a -> RecordField s a # | |
(Show s, Show a) => Show (RecordField s a) Source # | |
Defined in Dhall.Syntax showsPrec :: Int -> RecordField s a -> ShowS # show :: RecordField s a -> String # showList :: [RecordField s a] -> ShowS # | |
Generic (RecordField s a) Source # | |
Defined in Dhall.Syntax type Rep (RecordField s a) :: Type -> Type # from :: RecordField s a -> Rep (RecordField s a) x # to :: Rep (RecordField s a) x -> RecordField s a # | |
(NFData s, NFData a) => NFData (RecordField s a) Source # | |
Defined in Dhall.Syntax rnf :: RecordField s a -> () # | |
type Rep (RecordField s a) Source # | |
Defined in Dhall.Syntax type Rep (RecordField s a) = D1 ('MetaData "RecordField" "Dhall.Syntax" "dhall-1.41.2-CygVEUAXWhKKGHhZSAzzm9" 'False) (C1 ('MetaCons "RecordField" 'PrefixI 'True) ((S1 ('MetaSel ('Just "recordFieldSrc0") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s)) :*: S1 ('MetaSel ('Just "recordFieldValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Expr s a))) :*: (S1 ('MetaSel ('Just "recordFieldSrc1") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s)) :*: S1 ('MetaSel ('Just "recordFieldSrc2") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe s))))) |
makeRecordField :: Expr s a -> RecordField s a Source #
Construct a RecordField
with no src information
data FunctionBinding s a Source #
Record the label of a function or a function-type expression
For example,
λ({- A -} a {- B -} : {- C -} T) -> e
… will be instantiated as follows:
functionBindingSrc0
corresponds to theA
commentfunctionBindingVariable
isa
functionBindingSrc1
corresponds to theB
commentfunctionBindingSrc2
corresponds to theC
commentfunctionBindingAnnotation
isT
FunctionBinding | |
|
Instances
makeFunctionBinding :: Text -> Expr s a -> FunctionBinding s a Source #
Smart constructor for FunctionBinding
with no src information
data FieldSelection s Source #
Record the field on a selector-expression
For example,
e . {- A -} x {- B -}
… will be instantiated as follows:
fieldSelectionSrc0
corresponds to theA
commentfieldSelectionLabel
corresponds tox
fieldSelectionSrc1
corresponds to theB
comment
Given our limitation that not all expressions recover their whitespaces, the
purpose of fieldSelectionSrc1
is to save the SourcePos
where the fieldSelectionLabel
ends, but we still use a 'Maybe Src'
(s =
) to be consistent with similar data types such as Src
Binding
, for
example.
FieldSelection | |
|
Instances
makeFieldSelection :: Text -> FieldSelection s Source #
Smart constructor for FieldSelection
with no src information
data WithComponent Source #
A path component for a with
expression
Instances
Syntax tree for expressions
The s
type parameter is used to track the presence or absence of Src
spans:
- If
s =
then the code may containsSrc
Src
spans (either in aNote
constructor or inline within another constructor, likeLet
) - If
s =
then the code has noVoid
Src
spans
The a
type parameter is used to track the presence or absence of imports
Const Const | Const c ~ c |
Var Var | Var (V x 0) ~ x Var (V x n) ~ x@n |
Lam (Maybe CharacterSet) (FunctionBinding s a) (Expr s a) | Lam _ (FunctionBinding _ "x" _ _ A) b ~ λ(x : A) -> b |
Pi (Maybe CharacterSet) Text (Expr s a) (Expr s a) | Pi _ "_" A B ~ A -> B Pi _ x A B ~ ∀(x : A) -> B |
App (Expr s a) (Expr s a) | App f a ~ f a |
Let (Binding s a) (Expr s a) | Let (Binding _ x _ Nothing _ r) e ~ let x = r in e Let (Binding _ x _ (Just t ) _ r) e ~ let x : t = r in e The difference between let x = a let y = b in e and let x = a in let y = b in e is only an additional See |
Annot (Expr s a) (Expr s a) | Annot x t ~ x : t |
Bool | Bool ~ Bool |
BoolLit Bool | BoolLit b ~ b |
BoolAnd (Expr s a) (Expr s a) | BoolAnd x y ~ x && y |
BoolOr (Expr s a) (Expr s a) | BoolOr x y ~ x || y |
BoolEQ (Expr s a) (Expr s a) | BoolEQ x y ~ x == y |
BoolNE (Expr s a) (Expr s a) | BoolNE x y ~ x != y |
BoolIf (Expr s a) (Expr s a) (Expr s a) | BoolIf x y z ~ if x then y else z |
Natural | Natural ~ Natural |
NaturalLit Natural | NaturalLit n ~ n |
NaturalFold | NaturalFold ~ Natural/fold |
NaturalBuild | NaturalBuild ~ Natural/build |
NaturalIsZero | NaturalIsZero ~ Natural/isZero |
NaturalEven | NaturalEven ~ Natural/even |
NaturalOdd | NaturalOdd ~ Natural/odd |
NaturalToInteger | NaturalToInteger ~ Natural/toInteger |
NaturalShow | NaturalShow ~ Natural/show |
NaturalSubtract | NaturalSubtract ~ Natural/subtract |
NaturalPlus (Expr s a) (Expr s a) | NaturalPlus x y ~ x + y |
NaturalTimes (Expr s a) (Expr s a) | NaturalTimes x y ~ x * y |
Integer | Integer ~ Integer |
IntegerLit Integer | IntegerLit n ~ ±n |
IntegerClamp | IntegerClamp ~ Integer/clamp |
IntegerNegate | IntegerNegate ~ Integer/negate |
IntegerShow | IntegerShow ~ Integer/show |
IntegerToDouble | IntegerToDouble ~ Integer/toDouble |
Double | Double ~ Double |
DoubleLit DhallDouble | DoubleLit n ~ n |
DoubleShow | DoubleShow ~ Double/show |
Text | Text ~ Text |
TextLit (Chunks s a) | TextLit (Chunks [(t1, e1), (t2, e2)] t3) ~ "t1${e1}t2${e2}t3" |
TextAppend (Expr s a) (Expr s a) | TextAppend x y ~ x ++ y |
TextReplace | TextReplace ~ Text/replace |
TextShow | TextShow ~ Text/show |
Date | Date ~ Date |
DateLiteral Day | DateLiteral (fromGregorian _YYYY _MM _DD) ~ YYYY-MM-DD |
Time | Time ~ Time |
TimeLiteral TimeOfDay Word | Precision | > TimeZone ~ TimeZone |
TimeZone | |
TimeZoneLiteral TimeZone | TimeZoneLiteral (TimeZone ( 60 * _HH + _MM) _ _) ~ +HH:MM | > TimeZoneLiteral (TimeZone (-60 * _HH + _MM) _ _) ~ -HH:MM |
List | List ~ List |
ListLit (Maybe (Expr s a)) (Seq (Expr s a)) | ListLit (Just t ) [] ~ [] : t ListLit Nothing [x, y, z] ~ [x, y, z] Invariant: A non-empty list literal is always represented as
When an annotated, non-empty list literal is parsed, it is represented as Annot (ListLit Nothing [x, y, z]) t ~ [x, y, z] : t |
ListAppend (Expr s a) (Expr s a) | ListAppend x y ~ x # y |
ListBuild | ListBuild ~ List/build |
ListFold | ListFold ~ List/fold |
ListLength | ListLength ~ List/length |
ListHead | ListHead ~ List/head |
ListLast | ListLast ~ List/last |
ListIndexed | ListIndexed ~ List/indexed |
ListReverse | ListReverse ~ List/reverse |
Optional | Optional ~ Optional |
Some (Expr s a) | Some e ~ Some e |
None | None ~ None |
Record (Map Text (RecordField s a)) | Record [ (k1, RecordField _ t1) ~ { k1 : t1, k2 : t1 } , (k2, RecordField _ t2) ] |
RecordLit (Map Text (RecordField s a)) | RecordLit [ (k1, RecordField _ v1) ~ { k1 = v1, k2 = v2 } , (k2, RecordField _ v2) ] |
Union (Map Text (Maybe (Expr s a))) | Union [(k1, Just t1), (k2, Nothing)] ~ < k1 : t1 | k2 > |
Combine (Maybe CharacterSet) (Maybe Text) (Expr s a) (Expr s a) | Combine _ Nothing x y ~ x ∧ y The first field is a RecordLit [ ( k ~ { k = x, k = y } , RecordField _ (Combine (Just k) x y) )] |
CombineTypes (Maybe CharacterSet) (Expr s a) (Expr s a) | CombineTypes _ x y ~ x ⩓ y |
Prefer (Maybe CharacterSet) (PreferAnnotation s a) (Expr s a) (Expr s a) | Prefer _ False x y ~ x ⫽ y The first field is a |
RecordCompletion (Expr s a) (Expr s a) | RecordCompletion x y ~ x::y |
Merge (Expr s a) (Expr s a) (Maybe (Expr s a)) | Merge x y (Just t ) ~ merge x y : t Merge x y Nothing ~ merge x y |
ToMap (Expr s a) (Maybe (Expr s a)) | ToMap x (Just t) ~ toMap x : t ToMap x Nothing ~ toMap x |
ShowConstructor (Expr s a) | ShowConstructor x ~ showConstructor x |
Field (Expr s a) (FieldSelection s) | Field e (FieldSelection _ x _) ~ e.x |
Project (Expr s a) (Either [Text] (Expr s a)) | Project e (Left xs) ~ e.{ xs } Project e (Right t) ~ e.(t) |
Assert (Expr s a) | Assert e ~ assert : e |
Equivalent (Maybe CharacterSet) (Expr s a) (Expr s a) | Equivalent _ x y ~ x ≡ y |
With (Expr s a) (NonEmpty WithComponent) (Expr s a) | With x y e ~ x with y = e |
Note s (Expr s a) | Note s x ~ e |
ImportAlt (Expr s a) (Expr s a) | ImportAlt ~ e1 ? e2 |
Embed a | Embed import ~ import |
Instances
Normalization
alphaNormalize :: Expr s a -> Expr s a Source #
α-normalize an expression by renaming all bound variables to "_"
and
using De Bruijn indices to distinguish them
>>>
mfb = Syntax.makeFunctionBinding
>>>
alphaNormalize (Lam mempty (mfb "a" (Const Type)) (Lam mempty (mfb "b" (Const Type)) (Lam mempty (mfb "x" "a") (Lam mempty (mfb "y" "b") "x"))))
Lam Nothing (FunctionBinding {functionBindingSrc0 = Nothing, functionBindingVariable = "_", functionBindingSrc1 = Nothing, functionBindingSrc2 = Nothing, functionBindingAnnotation = Const Type}) (Lam Nothing (FunctionBinding {functionBindingSrc0 = Nothing, functionBindingVariable = "_", functionBindingSrc1 = Nothing, functionBindingSrc2 = Nothing, functionBindingAnnotation = Const Type}) (Lam Nothing (FunctionBinding {functionBindingSrc0 = Nothing, functionBindingVariable = "_", functionBindingSrc1 = Nothing, functionBindingSrc2 = Nothing, functionBindingAnnotation = Var (V "_" 1)}) (Lam Nothing (FunctionBinding {functionBindingSrc0 = Nothing, functionBindingVariable = "_", functionBindingSrc1 = Nothing, functionBindingSrc2 = Nothing, functionBindingAnnotation = Var (V "_" 1)}) (Var (V "_" 1)))))
α-normalization does not affect free variables:
>>>
alphaNormalize "x"
Var (V "x" 0)
normalize :: Eq a => Expr s a -> Expr t a Source #
Reduce an expression to its normal form, performing beta reduction
normalize
does not type-check the expression. You may want to type-check
expressions before normalizing them since normalization can convert an
ill-typed expression into a well-typed expression.
normalize
can also fail with error
if you normalize an ill-typed
expression
normalizeWith :: Eq a => Maybe (ReifiedNormalizer a) -> Expr s a -> Expr t a Source #
Reduce an expression to its normal form, performing beta reduction and applying any custom definitions.
normalizeWith
is designed to be used with function typeWith
. The typeWith
function allows typing of Dhall functions in a custom typing context whereas
normalizeWith
allows evaluating Dhall expressions in a custom context.
To be more precise normalizeWith
applies the given normalizer when it finds an
application term that it cannot reduce by other means.
Note that the context used in normalization will determine the properties of normalization. That is, if the functions in custom context are not total then the Dhall language, evaluated with those functions is not total either.
normalizeWith
can fail with an error
if you normalize an ill-typed
expression
normalizeWithM :: (Monad m, Eq a) => NormalizerM m a -> Expr s a -> m (Expr t a) Source #
This function generalizes normalizeWith
by allowing the custom normalizer
to use an arbitrary Monad
normalizeWithM
can fail with an error
if you normalize an ill-typed
expression
type Normalizer a = NormalizerM Identity a Source #
An variation on NormalizerM
for pure normalizers
type NormalizerM m a = forall s. Expr s a -> m (Maybe (Expr s a)) Source #
Use this to wrap you embedded functions (see normalizeWith
) to make them
polymorphic enough to be used.
newtype ReifiedNormalizer a Source #
A reified Normalizer
, which can be stored in structures without
running into impredicative polymorphism.
judgmentallyEqual :: Eq a => Expr s a -> Expr t a -> Bool Source #
Returns True
if two expressions are α-equivalent and β-equivalent and
False
otherwise
judgmentallyEqual
can fail with an error
if you compare ill-typed
expressions
subst :: Var -> Expr s a -> Expr s a -> Expr s a Source #
Substitute all occurrences of a variable with an expression
subst x C B ~ B[x := C]
shift :: Int -> Var -> Expr s a -> Expr s a Source #
shift
is used by both normalization and type-checking to avoid variable
capture by shifting variable indices
For example, suppose that you were to normalize the following expression:
λ(a : Type) → λ(x : a) → (λ(y : a) → λ(x : a) → y) x
If you were to substitute y
with x
without shifting any variable
indices, then you would get the following incorrect result:
λ(a : Type) → λ(x : a) → λ(x : a) → x -- Incorrect normalized form
In order to substitute x
in place of y
we need to shift
x
by 1
in
order to avoid being misinterpreted as the x
bound by the innermost
lambda. If we perform that shift
then we get the correct result:
λ(a : Type) → λ(x : a) → λ(x : a) → x@1
As a more worked example, suppose that you were to normalize the following expression:
λ(a : Type) → λ(f : a → a → a) → λ(x : a) → λ(x : a) → (λ(x : a) → f x x@1) x@1
The correct normalized result would be:
λ(a : Type) → λ(f : a → a → a) → λ(x : a) → λ(x : a) → f x@1 x
The above example illustrates how we need to both increase and decrease variable indices as part of substitution:
- We need to increase the index of the outer
x@1
tox@2
before we substitute it into the body of the innermost lambda expression in order to avoid variable capture. This substitution changes the body of the lambda expression to(f x@2 x@1)
- We then remove the innermost lambda and therefore decrease the indices of
both
x
s in(f x@2 x@1)
to(f x@1 x)
in order to reflect that one lessx
variable is now bound within that scope
Formally, (shift d (V x n) e)
modifies the expression e
by adding d
to
the indices of all variables named x
whose indices are greater than
(n + m)
, where m
is the number of bound variables of the same name
within that scope
In practice, d
is always 1
or -1
because we either:
- increment variables by
1
to avoid variable capture during substitution - decrement variables by
1
when deleting lambdas after substitution
n
starts off at 0
when substitution begins and increments every time we
descend into a lambda or let expression that binds a variable of the same
name in order to avoid shifting the bound variables by mistake.
isNormalized :: Eq a => Expr s a -> Bool Source #
Quickly check if an expression is in normal form
Given a well-typed expression e
,
is equivalent to
isNormalized
ee ==
.normalize
e
Given an ill-typed expression, isNormalized
may fail with an error, or
evaluate to either False or True!
isNormalizedWith :: (Eq s, Eq a) => Normalizer a -> Expr s a -> Bool Source #
Check if an expression is in a normal form given a context of evaluation.
Unlike isNormalized
, this will fully normalize and traverse through the expression.
It is much more efficient to use isNormalized
.
isNormalizedWith
can fail with an error
if you check an ill-typed
expression
shallowDenote :: Expr s a -> Expr s a Source #
freeIn :: Eq a => Var -> Expr s a -> Bool Source #
Detect if the given variable is free within the given expression
>>>
"x" `freeIn` "x"
True>>>
"x" `freeIn` "y"
False>>>
"x" `freeIn` Lam mempty (Syntax.makeFunctionBinding "x" (Const Type)) "x"
False
Pretty-printing
Optics
subExpressions :: Applicative f => (Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a) Source #
A traversal over the immediate sub-expressions of an expression.
subExpressionsWith :: Applicative f => (a -> f (Expr s b)) -> (Expr s a -> f (Expr s b)) -> Expr s a -> f (Expr s b) Source #
A traversal over the immediate sub-expressions of an expression which allows mapping embedded values
chunkExprs :: Applicative f => (Expr s a -> f (Expr t b)) -> Chunks s a -> f (Chunks t b) Source #
A traversal over the immediate sub-expressions in Chunks
.
bindingExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> Binding s a -> f (Binding s b) Source #
recordFieldExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> RecordField s a -> f (RecordField s b) Source #
Traverse over the immediate Expr
children in a RecordField
.
functionBindingExprs :: Applicative f => (Expr s a -> f (Expr s b)) -> FunctionBinding s a -> f (FunctionBinding s b) Source #
Traverse over the immediate Expr
children in a FunctionBinding
.
Let-blocks
wrapInLets :: Foldable f => f (Binding s a) -> Expr s a -> Expr s a Source #
Wrap let-Binding
s around an Expr
.
wrapInLets
can be understood as an inverse for multiLet
:
let MultiLet bs e1 = multiLet b e0 wrapInLets bs e1 == Let b e0
This type represents 1 or more nested Let
bindings that have been
coalesced together for ease of manipulation
Miscellaneous
internalError :: Text -> forall b. b Source #
Utility function used to throw internal errors that should never happen (in theory) but that are not enforced by the type system
reservedIdentifiers :: HashSet Text Source #
The set of reserved identifiers for the Dhall language | Contains also all keywords from "reservedKeywords"
escapeText :: Text -> Text Source #
Escape a Text
literal using Dhall's escaping rules
Note that the result does not include surrounding quotes
pathCharacter :: Char -> Bool Source #
Returns True
if the given Char
is valid within an unquoted path
component
This is exported for reuse within the Dhall.Parser.Token
module