{-# LANGUAGE BangPatterns       #-}
{-# LANGUAGE CPP                #-}
{-# LANGUAGE DeriveAnyClass     #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE DeriveLift         #-}
{-# LANGUAGE DeriveTraversable  #-}
{-# LANGUAGE LambdaCase         #-}
{-# LANGUAGE OverloadedLists    #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RankNTypes         #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UnicodeSyntax      #-}

{-| This module contains the core syntax types and optics for them.

'reservedIdentifiers', 'denote' and friends are included because they are
involved in a dependency circle with "Dhall.Pretty.Internal".
-}

module Dhall.Syntax (
    -- * 'Expr'
      Const(..)
    , Var(..)
    , Binding(..)
    , makeBinding
    , Chunks(..)
    , DhallDouble(..)
    , PreferAnnotation(..)
    , Expr(..)

    -- ** 'Let'-blocks
    , MultiLet(..)
    , multiLet
    , wrapInLets

    -- ** Optics
    , subExpressions
    , unsafeSubExpressions
    , chunkExprs
    , bindingExprs

    -- ** Handling 'Note's
    , denote
    , renote
    , shallowDenote

    -- * 'Import'
    , Directory(..)
    , File(..)
    , FilePrefix(..)
    , Import(..)
    , ImportHashed(..)
    , ImportMode(..)
    , ImportType(..)
    , URL(..)
    , Scheme(..)
    , pathCharacter

    -- * Reserved identifiers
    , reservedIdentifiers

    -- * `Text` manipulation
    , toDoubleQuoted
    , longestSharedWhitespacePrefix
    , linesLiteral
    , unlinesLiteral

    -- * Desugaring
    , desugarWith

    -- * Utilities
    , internalError
    ) where

import Control.DeepSeq (NFData)
import Data.Bifunctor (Bifunctor(..))
import Data.Bits (xor)
import Data.Data (Data)
import Data.Foldable
import Data.HashSet (HashSet)
import Data.List.NonEmpty (NonEmpty(..))
import Data.String (IsString(..))
import Data.Semigroup (Semigroup(..))
import Data.Sequence (Seq)
import Data.Text (Text)
import Data.Text.Prettyprint.Doc (Doc, Pretty)
import Data.Traversable
import Data.Void (Void)
import Dhall.Map (Map)
import Dhall.Set (Set)
import Dhall.Src (Src(..))
import {-# SOURCE #-} Dhall.Pretty.Internal
import GHC.Generics (Generic)
import Instances.TH.Lift ()
import Language.Haskell.TH.Syntax (Lift)
import Numeric.Natural (Natural)
import Prelude hiding (succ)
import Unsafe.Coerce (unsafeCoerce)

import qualified Control.Monad
import qualified Data.HashSet
import qualified Data.List.NonEmpty         as NonEmpty
import qualified Data.Text
import qualified Data.Text.Prettyprint.Doc  as Pretty
import qualified Dhall.Crypto
import qualified Dhall.Optics               as Optics
import qualified Lens.Family                as Lens
import qualified Network.URI                as URI

{-| 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
-}
data Const = Type | Kind | Sort
    deriving (Int -> Const -> ShowS
[Const] -> ShowS
Const -> String
(Int -> Const -> ShowS)
-> (Const -> String) -> ([Const] -> ShowS) -> Show Const
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Const] -> ShowS
$cshowList :: [Const] -> ShowS
show :: Const -> String
$cshow :: Const -> String
showsPrec :: Int -> Const -> ShowS
$cshowsPrec :: Int -> Const -> ShowS
Show, Const -> Const -> Bool
(Const -> Const -> Bool) -> (Const -> Const -> Bool) -> Eq Const
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Const -> Const -> Bool
$c/= :: Const -> Const -> Bool
== :: Const -> Const -> Bool
$c== :: Const -> Const -> Bool
Eq, Eq Const
Eq Const =>
(Const -> Const -> Ordering)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Bool)
-> (Const -> Const -> Const)
-> (Const -> Const -> Const)
-> Ord Const
Const -> Const -> Bool
Const -> Const -> Ordering
Const -> Const -> Const
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Const -> Const -> Const
$cmin :: Const -> Const -> Const
max :: Const -> Const -> Const
$cmax :: Const -> Const -> Const
>= :: Const -> Const -> Bool
$c>= :: Const -> Const -> Bool
> :: Const -> Const -> Bool
$c> :: Const -> Const -> Bool
<= :: Const -> Const -> Bool
$c<= :: Const -> Const -> Bool
< :: Const -> Const -> Bool
$c< :: Const -> Const -> Bool
compare :: Const -> Const -> Ordering
$ccompare :: Const -> Const -> Ordering
$cp1Ord :: Eq Const
Ord, Typeable Const
DataType
Constr
Typeable Const =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Const -> c Const)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Const)
-> (Const -> Constr)
-> (Const -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Const))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const))
-> ((forall b. Data b => b -> b) -> Const -> Const)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r)
-> (forall u. (forall d. Data d => d -> u) -> Const -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Const -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Const -> m Const)
-> Data Const
Const -> DataType
Const -> Constr
(forall b. Data b => b -> b) -> Const -> Const
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Const -> u
forall u. (forall d. Data d => d -> u) -> Const -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Const -> m Const
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Const)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
$cSort :: Constr
$cKind :: Constr
$cType :: Constr
$tConst :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Const -> m Const
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapMp :: (forall d. Data d => d -> m d) -> Const -> m Const
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapM :: (forall d. Data d => d -> m d) -> Const -> m Const
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Const -> m Const
gmapQi :: Int -> (forall d. Data d => d -> u) -> Const -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Const -> u
gmapQ :: (forall d. Data d => d -> u) -> Const -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Const -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Const -> r
gmapT :: (forall b. Data b => b -> b) -> Const -> Const
$cgmapT :: (forall b. Data b => b -> b) -> Const -> Const
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Const)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Const)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Const)
dataTypeOf :: Const -> DataType
$cdataTypeOf :: Const -> DataType
toConstr :: Const -> Constr
$ctoConstr :: Const -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Const
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Const -> c Const
$cp1Data :: Typeable Const
Data, Const
Const -> Const -> Bounded Const
forall a. a -> a -> Bounded a
maxBound :: Const
$cmaxBound :: Const
minBound :: Const
$cminBound :: Const
Bounded, Int -> Const
Const -> Int
Const -> [Const]
Const -> Const
Const -> Const -> [Const]
Const -> Const -> Const -> [Const]
(Const -> Const)
-> (Const -> Const)
-> (Int -> Const)
-> (Const -> Int)
-> (Const -> [Const])
-> (Const -> Const -> [Const])
-> (Const -> Const -> [Const])
-> (Const -> Const -> Const -> [Const])
-> Enum Const
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Const -> Const -> Const -> [Const]
$cenumFromThenTo :: Const -> Const -> Const -> [Const]
enumFromTo :: Const -> Const -> [Const]
$cenumFromTo :: Const -> Const -> [Const]
enumFromThen :: Const -> Const -> [Const]
$cenumFromThen :: Const -> Const -> [Const]
enumFrom :: Const -> [Const]
$cenumFrom :: Const -> [Const]
fromEnum :: Const -> Int
$cfromEnum :: Const -> Int
toEnum :: Int -> Const
$ctoEnum :: Int -> Const
pred :: Const -> Const
$cpred :: Const -> Const
succ :: Const -> Const
$csucc :: Const -> Const
Enum, (forall x. Const -> Rep Const x)
-> (forall x. Rep Const x -> Const) -> Generic Const
forall x. Rep Const x -> Const
forall x. Const -> Rep Const x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Const x -> Const
$cfrom :: forall x. Const -> Rep Const x
Generic, Const -> Q Exp
(Const -> Q Exp) -> Lift Const
forall t. (t -> Q Exp) -> Lift t
lift :: Const -> Q Exp
$clift :: Const -> Q Exp
Lift, Const -> ()
(Const -> ()) -> NFData Const
forall a. (a -> ()) -> NFData a
rnf :: Const -> ()
$crnf :: Const -> ()
NFData)

instance Pretty Const where
    pretty :: Const -> Doc ann
pretty = Doc Ann -> Doc ann
forall ann xxx. Doc ann -> Doc xxx
Pretty.unAnnotate (Doc Ann -> Doc ann) -> (Const -> Doc Ann) -> Const -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Const -> Doc Ann
prettyConst

{-| 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.
-}
data Var = V Text !Int
    deriving (Typeable Var
DataType
Constr
Typeable Var =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Var -> c Var)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Var)
-> (Var -> Constr)
-> (Var -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Var))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var))
-> ((forall b. Data b => b -> b) -> Var -> Var)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r)
-> (forall u. (forall d. Data d => d -> u) -> Var -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Var -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Var -> m Var)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Var -> m Var)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Var -> m Var)
-> Data Var
Var -> DataType
Var -> Constr
(forall b. Data b => b -> b) -> Var -> Var
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Var -> c Var
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Var
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Var -> u
forall u. (forall d. Data d => d -> u) -> Var -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Var -> m Var
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Var -> m Var
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Var
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Var -> c Var
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Var)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var)
$cV :: Constr
$tVar :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Var -> m Var
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Var -> m Var
gmapMp :: (forall d. Data d => d -> m d) -> Var -> m Var
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Var -> m Var
gmapM :: (forall d. Data d => d -> m d) -> Var -> m Var
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Var -> m Var
gmapQi :: Int -> (forall d. Data d => d -> u) -> Var -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Var -> u
gmapQ :: (forall d. Data d => d -> u) -> Var -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Var -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r
gmapT :: (forall b. Data b => b -> b) -> Var -> Var
$cgmapT :: (forall b. Data b => b -> b) -> Var -> Var
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Var)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Var)
dataTypeOf :: Var -> DataType
$cdataTypeOf :: Var -> DataType
toConstr :: Var -> Constr
$ctoConstr :: Var -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Var
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Var
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Var -> c Var
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Var -> c Var
$cp1Data :: Typeable Var
Data, (forall x. Var -> Rep Var x)
-> (forall x. Rep Var x -> Var) -> Generic Var
forall x. Rep Var x -> Var
forall x. Var -> Rep Var x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Var x -> Var
$cfrom :: forall x. Var -> Rep Var x
Generic, Var -> Var -> Bool
(Var -> Var -> Bool) -> (Var -> Var -> Bool) -> Eq Var
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Var -> Var -> Bool
$c/= :: Var -> Var -> Bool
== :: Var -> Var -> Bool
$c== :: Var -> Var -> Bool
Eq, Eq Var
Eq Var =>
(Var -> Var -> Ordering)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Bool)
-> (Var -> Var -> Var)
-> (Var -> Var -> Var)
-> Ord Var
Var -> Var -> Bool
Var -> Var -> Ordering
Var -> Var -> Var
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Var -> Var -> Var
$cmin :: Var -> Var -> Var
max :: Var -> Var -> Var
$cmax :: Var -> Var -> Var
>= :: Var -> Var -> Bool
$c>= :: Var -> Var -> Bool
> :: Var -> Var -> Bool
$c> :: Var -> Var -> Bool
<= :: Var -> Var -> Bool
$c<= :: Var -> Var -> Bool
< :: Var -> Var -> Bool
$c< :: Var -> Var -> Bool
compare :: Var -> Var -> Ordering
$ccompare :: Var -> Var -> Ordering
$cp1Ord :: Eq Var
Ord, Int -> Var -> ShowS
[Var] -> ShowS
Var -> String
(Int -> Var -> ShowS)
-> (Var -> String) -> ([Var] -> ShowS) -> Show Var
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Var] -> ShowS
$cshowList :: [Var] -> ShowS
show :: Var -> String
$cshow :: Var -> String
showsPrec :: Int -> Var -> ShowS
$cshowsPrec :: Int -> Var -> ShowS
Show, Var -> Q Exp
(Var -> Q Exp) -> Lift Var
forall t. (t -> Q Exp) -> Lift t
lift :: Var -> Q Exp
$clift :: Var -> Q Exp
Lift, Var -> ()
(Var -> ()) -> NFData Var
forall a. (a -> ()) -> NFData a
rnf :: Var -> ()
$crnf :: Var -> ()
NFData)

instance IsString Var where
    fromString :: String -> Var
fromString str :: String
str = Text -> Int -> Var
V (String -> Text
forall a. IsString a => String -> a
fromString String
str) 0

instance Pretty Var where
    pretty :: Var -> Doc ann
pretty = Doc Ann -> Doc ann
forall ann xxx. Doc ann -> Doc xxx
Pretty.unAnnotate (Doc Ann -> Doc ann) -> (Var -> Doc Ann) -> Var -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Doc Ann
prettyVar

{- | 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 the @A@ comment.
* @variable@ is @"x"@
* @bindingSrc1@ corresponds to the @B@ comment.
* @annotation@ is 'Just' a pair, corresponding to the @C@ comment and @Bool@.
* @bindingSrc2@ corresponds to the @D@ comment.
* @value@ corresponds to @True@.
-}
data Binding s a = Binding
    { Binding s a -> Maybe s
bindingSrc0 :: Maybe s
    , Binding s a -> Text
variable    :: Text
    , Binding s a -> Maybe s
bindingSrc1 :: Maybe s
    , Binding s a -> Maybe (Maybe s, Expr s a)
annotation  :: Maybe (Maybe s, Expr s a)
    , Binding s a -> Maybe s
bindingSrc2 :: Maybe s
    , Binding s a -> Expr s a
value       :: Expr s a
    } deriving (Typeable (Binding s a)
DataType
Constr
Typeable (Binding s a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Binding s a -> c (Binding s a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Binding s a))
-> (Binding s a -> Constr)
-> (Binding s a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Binding s a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Binding s a)))
-> ((forall b. Data b => b -> b) -> Binding s a -> Binding s a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Binding s a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Binding s a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Binding s a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Binding s a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a))
-> Data (Binding s a)
Binding s a -> DataType
Binding s a -> Constr
(forall b. Data b => b -> b) -> Binding s a -> Binding s a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binding s a -> c (Binding s a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binding s a)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Binding s a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Binding s a -> u
forall u. (forall d. Data d => d -> u) -> Binding s a -> [u]
forall s a. (Data s, Data a) => Typeable (Binding s a)
forall s a. (Data s, Data a) => Binding s a -> DataType
forall s a. (Data s, Data a) => Binding s a -> Constr
forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Binding s a -> Binding s a
forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Binding s a -> u
forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Binding s a -> [u]
forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binding s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binding s a -> c (Binding s a)
forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Binding s a))
forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Binding s a))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binding s a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binding s a -> c (Binding s a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Binding s a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Binding s a))
$cBinding :: Constr
$tBinding :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
$cgmapMo :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
gmapMp :: (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
$cgmapMp :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
gmapM :: (forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
$cgmapM :: forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Binding s a -> m (Binding s a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Binding s a -> u
$cgmapQi :: forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Binding s a -> u
gmapQ :: (forall d. Data d => d -> u) -> Binding s a -> [u]
$cgmapQ :: forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Binding s a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
$cgmapQr :: forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
$cgmapQl :: forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Binding s a -> r
gmapT :: (forall b. Data b => b -> b) -> Binding s a -> Binding s a
$cgmapT :: forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Binding s a -> Binding s a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Binding s a))
$cdataCast2 :: forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Binding s a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Binding s a))
$cdataCast1 :: forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Binding s a))
dataTypeOf :: Binding s a -> DataType
$cdataTypeOf :: forall s a. (Data s, Data a) => Binding s a -> DataType
toConstr :: Binding s a -> Constr
$ctoConstr :: forall s a. (Data s, Data a) => Binding s a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binding s a)
$cgunfold :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Binding s a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binding s a -> c (Binding s a)
$cgfoldl :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Binding s a -> c (Binding s a)
$cp1Data :: forall s a. (Data s, Data a) => Typeable (Binding s a)
Data, Binding s a -> Binding s a -> Bool
(Binding s a -> Binding s a -> Bool)
-> (Binding s a -> Binding s a -> Bool) -> Eq (Binding s a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall s a. (Eq s, Eq a) => Binding s a -> Binding s a -> Bool
/= :: Binding s a -> Binding s a -> Bool
$c/= :: forall s a. (Eq s, Eq a) => Binding s a -> Binding s a -> Bool
== :: Binding s a -> Binding s a -> Bool
$c== :: forall s a. (Eq s, Eq a) => Binding s a -> Binding s a -> Bool
Eq, Binding s a -> Bool
(a -> m) -> Binding s a -> m
(a -> b -> b) -> b -> Binding s a -> b
(forall m. Monoid m => Binding s m -> m)
-> (forall m a. Monoid m => (a -> m) -> Binding s a -> m)
-> (forall m a. Monoid m => (a -> m) -> Binding s a -> m)
-> (forall a b. (a -> b -> b) -> b -> Binding s a -> b)
-> (forall a b. (a -> b -> b) -> b -> Binding s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Binding s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Binding s a -> b)
-> (forall a. (a -> a -> a) -> Binding s a -> a)
-> (forall a. (a -> a -> a) -> Binding s a -> a)
-> (forall a. Binding s a -> [a])
-> (forall a. Binding s a -> Bool)
-> (forall a. Binding s a -> Int)
-> (forall a. Eq a => a -> Binding s a -> Bool)
-> (forall a. Ord a => Binding s a -> a)
-> (forall a. Ord a => Binding s a -> a)
-> (forall a. Num a => Binding s a -> a)
-> (forall a. Num a => Binding s a -> a)
-> Foldable (Binding s)
forall a. Eq a => a -> Binding s a -> Bool
forall a. Num a => Binding s a -> a
forall a. Ord a => Binding s a -> a
forall m. Monoid m => Binding s m -> m
forall a. Binding s a -> Bool
forall a. Binding s a -> Int
forall a. Binding s a -> [a]
forall a. (a -> a -> a) -> Binding s a -> a
forall s a. Eq a => a -> Binding s a -> Bool
forall s a. Num a => Binding s a -> a
forall s a. Ord a => Binding s a -> a
forall m a. Monoid m => (a -> m) -> Binding s a -> m
forall s m. Monoid m => Binding s m -> m
forall s a. Binding s a -> Bool
forall s a. Binding s a -> Int
forall s a. Binding s a -> [a]
forall b a. (b -> a -> b) -> b -> Binding s a -> b
forall a b. (a -> b -> b) -> b -> Binding s a -> b
forall s a. (a -> a -> a) -> Binding s a -> a
forall s m a. Monoid m => (a -> m) -> Binding s a -> m
forall s b a. (b -> a -> b) -> b -> Binding s a -> b
forall s a b. (a -> b -> b) -> b -> Binding s a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Binding s a -> a
$cproduct :: forall s a. Num a => Binding s a -> a
sum :: Binding s a -> a
$csum :: forall s a. Num a => Binding s a -> a
minimum :: Binding s a -> a
$cminimum :: forall s a. Ord a => Binding s a -> a
maximum :: Binding s a -> a
$cmaximum :: forall s a. Ord a => Binding s a -> a
elem :: a -> Binding s a -> Bool
$celem :: forall s a. Eq a => a -> Binding s a -> Bool
length :: Binding s a -> Int
$clength :: forall s a. Binding s a -> Int
null :: Binding s a -> Bool
$cnull :: forall s a. Binding s a -> Bool
toList :: Binding s a -> [a]
$ctoList :: forall s a. Binding s a -> [a]
foldl1 :: (a -> a -> a) -> Binding s a -> a
$cfoldl1 :: forall s a. (a -> a -> a) -> Binding s a -> a
foldr1 :: (a -> a -> a) -> Binding s a -> a
$cfoldr1 :: forall s a. (a -> a -> a) -> Binding s a -> a
foldl' :: (b -> a -> b) -> b -> Binding s a -> b
$cfoldl' :: forall s b a. (b -> a -> b) -> b -> Binding s a -> b
foldl :: (b -> a -> b) -> b -> Binding s a -> b
$cfoldl :: forall s b a. (b -> a -> b) -> b -> Binding s a -> b
foldr' :: (a -> b -> b) -> b -> Binding s a -> b
$cfoldr' :: forall s a b. (a -> b -> b) -> b -> Binding s a -> b
foldr :: (a -> b -> b) -> b -> Binding s a -> b
$cfoldr :: forall s a b. (a -> b -> b) -> b -> Binding s a -> b
foldMap' :: (a -> m) -> Binding s a -> m
$cfoldMap' :: forall s m a. Monoid m => (a -> m) -> Binding s a -> m
foldMap :: (a -> m) -> Binding s a -> m
$cfoldMap :: forall s m a. Monoid m => (a -> m) -> Binding s a -> m
fold :: Binding s m -> m
$cfold :: forall s m. Monoid m => Binding s m -> m
Foldable, a -> Binding s b -> Binding s a
(a -> b) -> Binding s a -> Binding s b
(forall a b. (a -> b) -> Binding s a -> Binding s b)
-> (forall a b. a -> Binding s b -> Binding s a)
-> Functor (Binding s)
forall a b. a -> Binding s b -> Binding s a
forall a b. (a -> b) -> Binding s a -> Binding s b
forall s a b. a -> Binding s b -> Binding s a
forall s a b. (a -> b) -> Binding s a -> Binding s b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Binding s b -> Binding s a
$c<$ :: forall s a b. a -> Binding s b -> Binding s a
fmap :: (a -> b) -> Binding s a -> Binding s b
$cfmap :: forall s a b. (a -> b) -> Binding s a -> Binding s b
Functor, (forall x. Binding s a -> Rep (Binding s a) x)
-> (forall x. Rep (Binding s a) x -> Binding s a)
-> Generic (Binding s a)
forall x. Rep (Binding s a) x -> Binding s a
forall x. Binding s a -> Rep (Binding s a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s a x. Rep (Binding s a) x -> Binding s a
forall s a x. Binding s a -> Rep (Binding s a) x
$cto :: forall s a x. Rep (Binding s a) x -> Binding s a
$cfrom :: forall s a x. Binding s a -> Rep (Binding s a) x
Generic, Binding s a -> Q Exp
(Binding s a -> Q Exp) -> Lift (Binding s a)
forall t. (t -> Q Exp) -> Lift t
forall s a. (Lift s, Lift a) => Binding s a -> Q Exp
lift :: Binding s a -> Q Exp
$clift :: forall s a. (Lift s, Lift a) => Binding s a -> Q Exp
Lift, Binding s a -> ()
(Binding s a -> ()) -> NFData (Binding s a)
forall a. (a -> ()) -> NFData a
forall s a. (NFData s, NFData a) => Binding s a -> ()
rnf :: Binding s a -> ()
$crnf :: forall s a. (NFData s, NFData a) => Binding s a -> ()
NFData, Eq (Binding s a)
Eq (Binding s a) =>
(Binding s a -> Binding s a -> Ordering)
-> (Binding s a -> Binding s a -> Bool)
-> (Binding s a -> Binding s a -> Bool)
-> (Binding s a -> Binding s a -> Bool)
-> (Binding s a -> Binding s a -> Bool)
-> (Binding s a -> Binding s a -> Binding s a)
-> (Binding s a -> Binding s a -> Binding s a)
-> Ord (Binding s a)
Binding s a -> Binding s a -> Bool
Binding s a -> Binding s a -> Ordering
Binding s a -> Binding s a -> Binding s a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall s a. (Ord s, Ord a) => Eq (Binding s a)
forall s a. (Ord s, Ord a) => Binding s a -> Binding s a -> Bool
forall s a.
(Ord s, Ord a) =>
Binding s a -> Binding s a -> Ordering
forall s a.
(Ord s, Ord a) =>
Binding s a -> Binding s a -> Binding s a
min :: Binding s a -> Binding s a -> Binding s a
$cmin :: forall s a.
(Ord s, Ord a) =>
Binding s a -> Binding s a -> Binding s a
max :: Binding s a -> Binding s a -> Binding s a
$cmax :: forall s a.
(Ord s, Ord a) =>
Binding s a -> Binding s a -> Binding s a
>= :: Binding s a -> Binding s a -> Bool
$c>= :: forall s a. (Ord s, Ord a) => Binding s a -> Binding s a -> Bool
> :: Binding s a -> Binding s a -> Bool
$c> :: forall s a. (Ord s, Ord a) => Binding s a -> Binding s a -> Bool
<= :: Binding s a -> Binding s a -> Bool
$c<= :: forall s a. (Ord s, Ord a) => Binding s a -> Binding s a -> Bool
< :: Binding s a -> Binding s a -> Bool
$c< :: forall s a. (Ord s, Ord a) => Binding s a -> Binding s a -> Bool
compare :: Binding s a -> Binding s a -> Ordering
$ccompare :: forall s a.
(Ord s, Ord a) =>
Binding s a -> Binding s a -> Ordering
$cp1Ord :: forall s a. (Ord s, Ord a) => Eq (Binding s a)
Ord, Int -> Binding s a -> ShowS
[Binding s a] -> ShowS
Binding s a -> String
(Int -> Binding s a -> ShowS)
-> (Binding s a -> String)
-> ([Binding s a] -> ShowS)
-> Show (Binding s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s a. (Show s, Show a) => Int -> Binding s a -> ShowS
forall s a. (Show s, Show a) => [Binding s a] -> ShowS
forall s a. (Show s, Show a) => Binding s a -> String
showList :: [Binding s a] -> ShowS
$cshowList :: forall s a. (Show s, Show a) => [Binding s a] -> ShowS
show :: Binding s a -> String
$cshow :: forall s a. (Show s, Show a) => Binding s a -> String
showsPrec :: Int -> Binding s a -> ShowS
$cshowsPrec :: forall s a. (Show s, Show a) => Int -> Binding s a -> ShowS
Show, Functor (Binding s)
Foldable (Binding s)
(Functor (Binding s), Foldable (Binding s)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Binding s a -> f (Binding s b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Binding s (f a) -> f (Binding s a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Binding s a -> m (Binding s b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Binding s (m a) -> m (Binding s a))
-> Traversable (Binding s)
(a -> f b) -> Binding s a -> f (Binding s b)
forall s. Functor (Binding s)
forall s. Foldable (Binding s)
forall s (m :: * -> *) a.
Monad m =>
Binding s (m a) -> m (Binding s a)
forall s (f :: * -> *) a.
Applicative f =>
Binding s (f a) -> f (Binding s a)
forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binding s a -> m (Binding s b)
forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binding s a -> f (Binding s b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
Binding s (m a) -> m (Binding s a)
forall (f :: * -> *) a.
Applicative f =>
Binding s (f a) -> f (Binding s a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binding s a -> m (Binding s b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binding s a -> f (Binding s b)
sequence :: Binding s (m a) -> m (Binding s a)
$csequence :: forall s (m :: * -> *) a.
Monad m =>
Binding s (m a) -> m (Binding s a)
mapM :: (a -> m b) -> Binding s a -> m (Binding s b)
$cmapM :: forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Binding s a -> m (Binding s b)
sequenceA :: Binding s (f a) -> f (Binding s a)
$csequenceA :: forall s (f :: * -> *) a.
Applicative f =>
Binding s (f a) -> f (Binding s a)
traverse :: (a -> f b) -> Binding s a -> f (Binding s b)
$ctraverse :: forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Binding s a -> f (Binding s b)
$cp2Traversable :: forall s. Foldable (Binding s)
$cp1Traversable :: forall s. Functor (Binding s)
Traversable)

instance Bifunctor Binding where
    first :: (a -> b) -> Binding a c -> Binding b c
first k :: a -> b
k (Binding src0 :: Maybe a
src0 a :: Text
a src1 :: Maybe a
src1 b :: Maybe (Maybe a, Expr a c)
b src2 :: Maybe a
src2 c :: Expr a c
c) =
        Maybe b
-> Text
-> Maybe b
-> Maybe (Maybe b, Expr b c)
-> Maybe b
-> Expr b c
-> Binding b c
forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding ((a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src0) Text
a ((a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src1) (((Maybe a, Expr a c) -> (Maybe b, Expr b c))
-> Maybe (Maybe a, Expr a c) -> Maybe (Maybe b, Expr b c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe a, Expr a c) -> (Maybe b, Expr b c)
forall (f :: * -> *) (p :: * -> * -> *) c.
(Functor f, Bifunctor p) =>
(f a, p a c) -> (f b, p b c)
adapt0 Maybe (Maybe a, Expr a c)
b) ((a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k Maybe a
src2) ((a -> b) -> Expr a c -> Expr b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
c)
      where
        adapt0 :: (f a, p a c) -> (f b, p b c)
adapt0 (src3 :: f a
src3, d :: p a c
d) = ((a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
k f a
src3, (a -> b) -> p a c -> p b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k p a c
d)

    second :: (b -> c) -> Binding a b -> Binding a c
second = (b -> c) -> Binding a b -> Binding a c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

{-| Construct a 'Binding' with no source information and no type annotation.
-}
makeBinding :: Text -> Expr s a -> Binding s a
makeBinding :: Text -> Expr s a -> Binding s a
makeBinding name :: Text
name = Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding Maybe s
forall a. Maybe a
Nothing Text
name Maybe s
forall a. Maybe a
Nothing Maybe (Maybe s, Expr s a)
forall a. Maybe a
Nothing Maybe s
forall a. Maybe a
Nothing

-- | This wrapper around 'Prelude.Double' exists for its 'Eq' instance which is
-- defined via the binary encoding of Dhall @Double@s.
newtype DhallDouble = DhallDouble { DhallDouble -> Double
getDhallDouble :: Double }
    deriving (Int -> DhallDouble -> ShowS
[DhallDouble] -> ShowS
DhallDouble -> String
(Int -> DhallDouble -> ShowS)
-> (DhallDouble -> String)
-> ([DhallDouble] -> ShowS)
-> Show DhallDouble
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DhallDouble] -> ShowS
$cshowList :: [DhallDouble] -> ShowS
show :: DhallDouble -> String
$cshow :: DhallDouble -> String
showsPrec :: Int -> DhallDouble -> ShowS
$cshowsPrec :: Int -> DhallDouble -> ShowS
Show, Typeable DhallDouble
DataType
Constr
Typeable DhallDouble =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> DhallDouble -> c DhallDouble)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c DhallDouble)
-> (DhallDouble -> Constr)
-> (DhallDouble -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c DhallDouble))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c DhallDouble))
-> ((forall b. Data b => b -> b) -> DhallDouble -> DhallDouble)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> DhallDouble -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> DhallDouble -> r)
-> (forall u. (forall d. Data d => d -> u) -> DhallDouble -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> DhallDouble -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble)
-> Data DhallDouble
DhallDouble -> DataType
DhallDouble -> Constr
(forall b. Data b => b -> b) -> DhallDouble -> DhallDouble
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DhallDouble -> c DhallDouble
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DhallDouble
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> DhallDouble -> u
forall u. (forall d. Data d => d -> u) -> DhallDouble -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DhallDouble
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DhallDouble -> c DhallDouble
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DhallDouble)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DhallDouble)
$cDhallDouble :: Constr
$tDhallDouble :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
gmapMp :: (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
gmapM :: (forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> DhallDouble -> m DhallDouble
gmapQi :: Int -> (forall d. Data d => d -> u) -> DhallDouble -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> DhallDouble -> u
gmapQ :: (forall d. Data d => d -> u) -> DhallDouble -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> DhallDouble -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> DhallDouble -> r
gmapT :: (forall b. Data b => b -> b) -> DhallDouble -> DhallDouble
$cgmapT :: (forall b. Data b => b -> b) -> DhallDouble -> DhallDouble
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DhallDouble)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c DhallDouble)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c DhallDouble)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c DhallDouble)
dataTypeOf :: DhallDouble -> DataType
$cdataTypeOf :: DhallDouble -> DataType
toConstr :: DhallDouble -> Constr
$ctoConstr :: DhallDouble -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DhallDouble
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c DhallDouble
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DhallDouble -> c DhallDouble
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> DhallDouble -> c DhallDouble
$cp1Data :: Typeable DhallDouble
Data, DhallDouble -> Q Exp
(DhallDouble -> Q Exp) -> Lift DhallDouble
forall t. (t -> Q Exp) -> Lift t
lift :: DhallDouble -> Q Exp
$clift :: DhallDouble -> Q Exp
Lift, DhallDouble -> ()
(DhallDouble -> ()) -> NFData DhallDouble
forall a. (a -> ()) -> NFData a
rnf :: DhallDouble -> ()
$crnf :: DhallDouble -> ()
NFData, (forall x. DhallDouble -> Rep DhallDouble x)
-> (forall x. Rep DhallDouble x -> DhallDouble)
-> Generic DhallDouble
forall x. Rep DhallDouble x -> DhallDouble
forall x. DhallDouble -> Rep DhallDouble x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DhallDouble x -> DhallDouble
$cfrom :: forall x. DhallDouble -> Rep DhallDouble x
Generic)

-- | This instance satisfies all the customary 'Eq' laws except substitutivity.
--
-- In particular:
--
-- >>> nan = DhallDouble (0/0)
-- >>> nan == nan
-- True
--
-- This instance is also consistent with with the binary encoding of Dhall @Double@s:
--
-- >>> toBytes n = Dhall.Binary.encodeExpression (DoubleLit n :: Expr Void Import)
--
-- prop> \a b -> (a == b) == (toBytes a == toBytes b)
instance Eq DhallDouble where
    DhallDouble a :: Double
a == :: DhallDouble -> DhallDouble -> Bool
== DhallDouble b :: Double
b
        | Double -> Bool
forall a. RealFloat a => a -> Bool
isNaN Double
a Bool -> Bool -> Bool
&& Double -> Bool
forall a. RealFloat a => a -> Bool
isNaN Double
b                      = Bool
True
        | Double -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero Double
a Bool -> Bool -> Bool
forall a. Bits a => a -> a -> a
`xor` Double -> Bool
forall a. RealFloat a => a -> Bool
isNegativeZero Double
b = Bool
False
        | Bool
otherwise                               = Double
a Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
b

-- | This instance relies on the 'Eq' instance for 'DhallDouble' but cannot
-- satisfy the customary 'Ord' laws when @NaN@ is involved.
instance Ord DhallDouble where
    compare :: DhallDouble -> DhallDouble -> Ordering
compare a :: DhallDouble
a@(DhallDouble a' :: Double
a') b :: DhallDouble
b@(DhallDouble b' :: Double
b') =
        if DhallDouble
a DhallDouble -> DhallDouble -> Bool
forall a. Eq a => a -> a -> Bool
== DhallDouble
b
            then Ordering
EQ
            else Double -> Double -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Double
a' Double
b'

-- | The body of an interpolated @Text@ literal
data Chunks s a = Chunks [(Text, Expr s a)] Text
    deriving (a -> Chunks s b -> Chunks s a
(a -> b) -> Chunks s a -> Chunks s b
(forall a b. (a -> b) -> Chunks s a -> Chunks s b)
-> (forall a b. a -> Chunks s b -> Chunks s a)
-> Functor (Chunks s)
forall a b. a -> Chunks s b -> Chunks s a
forall a b. (a -> b) -> Chunks s a -> Chunks s b
forall s a b. a -> Chunks s b -> Chunks s a
forall s a b. (a -> b) -> Chunks s a -> Chunks s b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Chunks s b -> Chunks s a
$c<$ :: forall s a b. a -> Chunks s b -> Chunks s a
fmap :: (a -> b) -> Chunks s a -> Chunks s b
$cfmap :: forall s a b. (a -> b) -> Chunks s a -> Chunks s b
Functor, Chunks s a -> Bool
(a -> m) -> Chunks s a -> m
(a -> b -> b) -> b -> Chunks s a -> b
(forall m. Monoid m => Chunks s m -> m)
-> (forall m a. Monoid m => (a -> m) -> Chunks s a -> m)
-> (forall m a. Monoid m => (a -> m) -> Chunks s a -> m)
-> (forall a b. (a -> b -> b) -> b -> Chunks s a -> b)
-> (forall a b. (a -> b -> b) -> b -> Chunks s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Chunks s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Chunks s a -> b)
-> (forall a. (a -> a -> a) -> Chunks s a -> a)
-> (forall a. (a -> a -> a) -> Chunks s a -> a)
-> (forall a. Chunks s a -> [a])
-> (forall a. Chunks s a -> Bool)
-> (forall a. Chunks s a -> Int)
-> (forall a. Eq a => a -> Chunks s a -> Bool)
-> (forall a. Ord a => Chunks s a -> a)
-> (forall a. Ord a => Chunks s a -> a)
-> (forall a. Num a => Chunks s a -> a)
-> (forall a. Num a => Chunks s a -> a)
-> Foldable (Chunks s)
forall a. Eq a => a -> Chunks s a -> Bool
forall a. Num a => Chunks s a -> a
forall a. Ord a => Chunks s a -> a
forall m. Monoid m => Chunks s m -> m
forall a. Chunks s a -> Bool
forall a. Chunks s a -> Int
forall a. Chunks s a -> [a]
forall a. (a -> a -> a) -> Chunks s a -> a
forall s a. Eq a => a -> Chunks s a -> Bool
forall s a. Num a => Chunks s a -> a
forall s a. Ord a => Chunks s a -> a
forall m a. Monoid m => (a -> m) -> Chunks s a -> m
forall s m. Monoid m => Chunks s m -> m
forall s a. Chunks s a -> Bool
forall s a. Chunks s a -> Int
forall s a. Chunks s a -> [a]
forall b a. (b -> a -> b) -> b -> Chunks s a -> b
forall a b. (a -> b -> b) -> b -> Chunks s a -> b
forall s a. (a -> a -> a) -> Chunks s a -> a
forall s m a. Monoid m => (a -> m) -> Chunks s a -> m
forall s b a. (b -> a -> b) -> b -> Chunks s a -> b
forall s a b. (a -> b -> b) -> b -> Chunks s a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Chunks s a -> a
$cproduct :: forall s a. Num a => Chunks s a -> a
sum :: Chunks s a -> a
$csum :: forall s a. Num a => Chunks s a -> a
minimum :: Chunks s a -> a
$cminimum :: forall s a. Ord a => Chunks s a -> a
maximum :: Chunks s a -> a
$cmaximum :: forall s a. Ord a => Chunks s a -> a
elem :: a -> Chunks s a -> Bool
$celem :: forall s a. Eq a => a -> Chunks s a -> Bool
length :: Chunks s a -> Int
$clength :: forall s a. Chunks s a -> Int
null :: Chunks s a -> Bool
$cnull :: forall s a. Chunks s a -> Bool
toList :: Chunks s a -> [a]
$ctoList :: forall s a. Chunks s a -> [a]
foldl1 :: (a -> a -> a) -> Chunks s a -> a
$cfoldl1 :: forall s a. (a -> a -> a) -> Chunks s a -> a
foldr1 :: (a -> a -> a) -> Chunks s a -> a
$cfoldr1 :: forall s a. (a -> a -> a) -> Chunks s a -> a
foldl' :: (b -> a -> b) -> b -> Chunks s a -> b
$cfoldl' :: forall s b a. (b -> a -> b) -> b -> Chunks s a -> b
foldl :: (b -> a -> b) -> b -> Chunks s a -> b
$cfoldl :: forall s b a. (b -> a -> b) -> b -> Chunks s a -> b
foldr' :: (a -> b -> b) -> b -> Chunks s a -> b
$cfoldr' :: forall s a b. (a -> b -> b) -> b -> Chunks s a -> b
foldr :: (a -> b -> b) -> b -> Chunks s a -> b
$cfoldr :: forall s a b. (a -> b -> b) -> b -> Chunks s a -> b
foldMap' :: (a -> m) -> Chunks s a -> m
$cfoldMap' :: forall s m a. Monoid m => (a -> m) -> Chunks s a -> m
foldMap :: (a -> m) -> Chunks s a -> m
$cfoldMap :: forall s m a. Monoid m => (a -> m) -> Chunks s a -> m
fold :: Chunks s m -> m
$cfold :: forall s m. Monoid m => Chunks s m -> m
Foldable, (forall x. Chunks s a -> Rep (Chunks s a) x)
-> (forall x. Rep (Chunks s a) x -> Chunks s a)
-> Generic (Chunks s a)
forall x. Rep (Chunks s a) x -> Chunks s a
forall x. Chunks s a -> Rep (Chunks s a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s a x. Rep (Chunks s a) x -> Chunks s a
forall s a x. Chunks s a -> Rep (Chunks s a) x
$cto :: forall s a x. Rep (Chunks s a) x -> Chunks s a
$cfrom :: forall s a x. Chunks s a -> Rep (Chunks s a) x
Generic, Functor (Chunks s)
Foldable (Chunks s)
(Functor (Chunks s), Foldable (Chunks s)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Chunks s a -> f (Chunks s b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Chunks s (f a) -> f (Chunks s a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Chunks s a -> m (Chunks s b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Chunks s (m a) -> m (Chunks s a))
-> Traversable (Chunks s)
(a -> f b) -> Chunks s a -> f (Chunks s b)
forall s. Functor (Chunks s)
forall s. Foldable (Chunks s)
forall s (m :: * -> *) a.
Monad m =>
Chunks s (m a) -> m (Chunks s a)
forall s (f :: * -> *) a.
Applicative f =>
Chunks s (f a) -> f (Chunks s a)
forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Chunks s a -> m (Chunks s b)
forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Chunks s a -> f (Chunks s b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Chunks s (m a) -> m (Chunks s a)
forall (f :: * -> *) a.
Applicative f =>
Chunks s (f a) -> f (Chunks s a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Chunks s a -> m (Chunks s b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Chunks s a -> f (Chunks s b)
sequence :: Chunks s (m a) -> m (Chunks s a)
$csequence :: forall s (m :: * -> *) a.
Monad m =>
Chunks s (m a) -> m (Chunks s a)
mapM :: (a -> m b) -> Chunks s a -> m (Chunks s b)
$cmapM :: forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Chunks s a -> m (Chunks s b)
sequenceA :: Chunks s (f a) -> f (Chunks s a)
$csequenceA :: forall s (f :: * -> *) a.
Applicative f =>
Chunks s (f a) -> f (Chunks s a)
traverse :: (a -> f b) -> Chunks s a -> f (Chunks s b)
$ctraverse :: forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Chunks s a -> f (Chunks s b)
$cp2Traversable :: forall s. Foldable (Chunks s)
$cp1Traversable :: forall s. Functor (Chunks s)
Traversable, Int -> Chunks s a -> ShowS
[Chunks s a] -> ShowS
Chunks s a -> String
(Int -> Chunks s a -> ShowS)
-> (Chunks s a -> String)
-> ([Chunks s a] -> ShowS)
-> Show (Chunks s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s a. (Show s, Show a) => Int -> Chunks s a -> ShowS
forall s a. (Show s, Show a) => [Chunks s a] -> ShowS
forall s a. (Show s, Show a) => Chunks s a -> String
showList :: [Chunks s a] -> ShowS
$cshowList :: forall s a. (Show s, Show a) => [Chunks s a] -> ShowS
show :: Chunks s a -> String
$cshow :: forall s a. (Show s, Show a) => Chunks s a -> String
showsPrec :: Int -> Chunks s a -> ShowS
$cshowsPrec :: forall s a. (Show s, Show a) => Int -> Chunks s a -> ShowS
Show, Chunks s a -> Chunks s a -> Bool
(Chunks s a -> Chunks s a -> Bool)
-> (Chunks s a -> Chunks s a -> Bool) -> Eq (Chunks s a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall s a. (Eq s, Eq a) => Chunks s a -> Chunks s a -> Bool
/= :: Chunks s a -> Chunks s a -> Bool
$c/= :: forall s a. (Eq s, Eq a) => Chunks s a -> Chunks s a -> Bool
== :: Chunks s a -> Chunks s a -> Bool
$c== :: forall s a. (Eq s, Eq a) => Chunks s a -> Chunks s a -> Bool
Eq, Eq (Chunks s a)
Eq (Chunks s a) =>
(Chunks s a -> Chunks s a -> Ordering)
-> (Chunks s a -> Chunks s a -> Bool)
-> (Chunks s a -> Chunks s a -> Bool)
-> (Chunks s a -> Chunks s a -> Bool)
-> (Chunks s a -> Chunks s a -> Bool)
-> (Chunks s a -> Chunks s a -> Chunks s a)
-> (Chunks s a -> Chunks s a -> Chunks s a)
-> Ord (Chunks s a)
Chunks s a -> Chunks s a -> Bool
Chunks s a -> Chunks s a -> Ordering
Chunks s a -> Chunks s a -> Chunks s a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall s a. (Ord s, Ord a) => Eq (Chunks s a)
forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Bool
forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Ordering
forall s a.
(Ord s, Ord a) =>
Chunks s a -> Chunks s a -> Chunks s a
min :: Chunks s a -> Chunks s a -> Chunks s a
$cmin :: forall s a.
(Ord s, Ord a) =>
Chunks s a -> Chunks s a -> Chunks s a
max :: Chunks s a -> Chunks s a -> Chunks s a
$cmax :: forall s a.
(Ord s, Ord a) =>
Chunks s a -> Chunks s a -> Chunks s a
>= :: Chunks s a -> Chunks s a -> Bool
$c>= :: forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Bool
> :: Chunks s a -> Chunks s a -> Bool
$c> :: forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Bool
<= :: Chunks s a -> Chunks s a -> Bool
$c<= :: forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Bool
< :: Chunks s a -> Chunks s a -> Bool
$c< :: forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Bool
compare :: Chunks s a -> Chunks s a -> Ordering
$ccompare :: forall s a. (Ord s, Ord a) => Chunks s a -> Chunks s a -> Ordering
$cp1Ord :: forall s a. (Ord s, Ord a) => Eq (Chunks s a)
Ord, Typeable (Chunks s a)
DataType
Constr
Typeable (Chunks s a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Chunks s a))
-> (Chunks s a -> Constr)
-> (Chunks s a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Chunks s a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Chunks s a)))
-> ((forall b. Data b => b -> b) -> Chunks s a -> Chunks s a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Chunks s a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Chunks s a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Chunks s a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Chunks s a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a))
-> Data (Chunks s a)
Chunks s a -> DataType
Chunks s a -> Constr
(forall b. Data b => b -> b) -> Chunks s a -> Chunks s a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Chunks s a)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Chunks s a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Chunks s a -> u
forall u. (forall d. Data d => d -> u) -> Chunks s a -> [u]
forall s a. (Data s, Data a) => Typeable (Chunks s a)
forall s a. (Data s, Data a) => Chunks s a -> DataType
forall s a. (Data s, Data a) => Chunks s a -> Constr
forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Chunks s a -> Chunks s a
forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Chunks s a -> u
forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Chunks s a -> [u]
forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Chunks s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a)
forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Chunks s a))
forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Chunks s a))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Chunks s a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Chunks s a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Chunks s a))
$cChunks :: Constr
$tChunks :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
$cgmapMo :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
gmapMp :: (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
$cgmapMp :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
gmapM :: (forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
$cgmapM :: forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Chunks s a -> m (Chunks s a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Chunks s a -> u
$cgmapQi :: forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Chunks s a -> u
gmapQ :: (forall d. Data d => d -> u) -> Chunks s a -> [u]
$cgmapQ :: forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Chunks s a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
$cgmapQr :: forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
$cgmapQl :: forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Chunks s a -> r
gmapT :: (forall b. Data b => b -> b) -> Chunks s a -> Chunks s a
$cgmapT :: forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Chunks s a -> Chunks s a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Chunks s a))
$cdataCast2 :: forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Chunks s a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Chunks s a))
$cdataCast1 :: forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Chunks s a))
dataTypeOf :: Chunks s a -> DataType
$cdataTypeOf :: forall s a. (Data s, Data a) => Chunks s a -> DataType
toConstr :: Chunks s a -> Constr
$ctoConstr :: forall s a. (Data s, Data a) => Chunks s a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Chunks s a)
$cgunfold :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Chunks s a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a)
$cgfoldl :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Chunks s a -> c (Chunks s a)
$cp1Data :: forall s a. (Data s, Data a) => Typeable (Chunks s a)
Data, Chunks s a -> Q Exp
(Chunks s a -> Q Exp) -> Lift (Chunks s a)
forall t. (t -> Q Exp) -> Lift t
forall s a. (Lift s, Lift a) => Chunks s a -> Q Exp
lift :: Chunks s a -> Q Exp
$clift :: forall s a. (Lift s, Lift a) => Chunks s a -> Q Exp
Lift, Chunks s a -> ()
(Chunks s a -> ()) -> NFData (Chunks s a)
forall a. (a -> ()) -> NFData a
forall s a. (NFData s, NFData a) => Chunks s a -> ()
rnf :: Chunks s a -> ()
$crnf :: forall s a. (NFData s, NFData a) => Chunks s a -> ()
NFData)

instance Data.Semigroup.Semigroup (Chunks s a) where
    Chunks xysL :: [(Text, Expr s a)]
xysL zL :: Text
zL <> :: Chunks s a -> Chunks s a -> Chunks s a
<> Chunks         []    zR :: Text
zR =
        [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks [(Text, Expr s a)]
xysL (Text
zL Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
zR)
    Chunks xysL :: [(Text, Expr s a)]
xysL zL :: Text
zL <> Chunks ((x :: Text
x, y :: Expr s a
y):xysR :: [(Text, Expr s a)]
xysR) zR :: Text
zR =
        [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks ([(Text, Expr s a)]
xysL [(Text, Expr s a)] -> [(Text, Expr s a)] -> [(Text, Expr s a)]
forall a. [a] -> [a] -> [a]
++ (Text
zL Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
x, Expr s a
y)(Text, Expr s a) -> [(Text, Expr s a)] -> [(Text, Expr s a)]
forall a. a -> [a] -> [a]
:[(Text, Expr s a)]
xysR) Text
zR

instance Monoid (Chunks s a) where
    mempty :: Chunks s a
mempty = [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks [] Text
forall a. Monoid a => a
mempty

#if !(MIN_VERSION_base(4,11,0))
    mappend = (<>)
#endif

instance IsString (Chunks s a) where
    fromString :: String -> Chunks s a
fromString str :: String
str = [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks [] (String -> Text
forall a. IsString a => String -> a
fromString String
str)

-- | Used to record the origin of a @//@ operator (i.e. from source code or a
-- product of desugaring)
data PreferAnnotation s a
    = PreferFromSource
    | PreferFromWith (Expr s a)
      -- ^ Stores the original @with@ expression
    | PreferFromCompletion
    deriving (Typeable (PreferAnnotation s a)
DataType
Constr
Typeable (PreferAnnotation s a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g)
 -> PreferAnnotation s a
 -> c (PreferAnnotation s a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a))
-> (PreferAnnotation s a -> Constr)
-> (PreferAnnotation s a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PreferAnnotation s a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PreferAnnotation s a)))
-> ((forall b. Data b => b -> b)
    -> PreferAnnotation s a -> PreferAnnotation s a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> PreferAnnotation s a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PreferAnnotation s a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> PreferAnnotation s a -> m (PreferAnnotation s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PreferAnnotation s a -> m (PreferAnnotation s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> PreferAnnotation s a -> m (PreferAnnotation s a))
-> Data (PreferAnnotation s a)
PreferAnnotation s a -> DataType
PreferAnnotation s a -> Constr
(forall b. Data b => b -> b)
-> PreferAnnotation s a -> PreferAnnotation s a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PreferAnnotation s a
-> c (PreferAnnotation s a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PreferAnnotation s a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> PreferAnnotation s a -> u
forall u.
(forall d. Data d => d -> u) -> PreferAnnotation s a -> [u]
forall s a. (Data s, Data a) => Typeable (PreferAnnotation s a)
forall s a. (Data s, Data a) => PreferAnnotation s a -> DataType
forall s a. (Data s, Data a) => PreferAnnotation s a -> Constr
forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b)
-> PreferAnnotation s a -> PreferAnnotation s a
forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> PreferAnnotation s a -> u
forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> PreferAnnotation s a -> [u]
forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PreferAnnotation s a
-> c (PreferAnnotation s a)
forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PreferAnnotation s a))
forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PreferAnnotation s a))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PreferAnnotation s a
-> c (PreferAnnotation s a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PreferAnnotation s a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PreferAnnotation s a))
$cPreferFromCompletion :: Constr
$cPreferFromWith :: Constr
$cPreferFromSource :: Constr
$tPreferAnnotation :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
$cgmapMo :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
gmapMp :: (forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
$cgmapMp :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
gmapM :: (forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
$cgmapM :: forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> PreferAnnotation s a -> m (PreferAnnotation s a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> PreferAnnotation s a -> u
$cgmapQi :: forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> PreferAnnotation s a -> u
gmapQ :: (forall d. Data d => d -> u) -> PreferAnnotation s a -> [u]
$cgmapQ :: forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> PreferAnnotation s a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
$cgmapQr :: forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
$cgmapQl :: forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PreferAnnotation s a -> r
gmapT :: (forall b. Data b => b -> b)
-> PreferAnnotation s a -> PreferAnnotation s a
$cgmapT :: forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b)
-> PreferAnnotation s a -> PreferAnnotation s a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PreferAnnotation s a))
$cdataCast2 :: forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PreferAnnotation s a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (PreferAnnotation s a))
$cdataCast1 :: forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PreferAnnotation s a))
dataTypeOf :: PreferAnnotation s a -> DataType
$cdataTypeOf :: forall s a. (Data s, Data a) => PreferAnnotation s a -> DataType
toConstr :: PreferAnnotation s a -> Constr
$ctoConstr :: forall s a. (Data s, Data a) => PreferAnnotation s a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a)
$cgunfold :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PreferAnnotation s a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PreferAnnotation s a
-> c (PreferAnnotation s a)
$cgfoldl :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PreferAnnotation s a
-> c (PreferAnnotation s a)
$cp1Data :: forall s a. (Data s, Data a) => Typeable (PreferAnnotation s a)
Data, PreferAnnotation s a -> PreferAnnotation s a -> Bool
(PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> (PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> Eq (PreferAnnotation s a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall s a.
(Eq s, Eq a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
/= :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c/= :: forall s a.
(Eq s, Eq a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
== :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c== :: forall s a.
(Eq s, Eq a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
Eq, PreferAnnotation s a -> Bool
(a -> m) -> PreferAnnotation s a -> m
(a -> b -> b) -> b -> PreferAnnotation s a -> b
(forall m. Monoid m => PreferAnnotation s m -> m)
-> (forall m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m)
-> (forall m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m)
-> (forall a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b)
-> (forall a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b)
-> (forall b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b)
-> (forall b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b)
-> (forall a. (a -> a -> a) -> PreferAnnotation s a -> a)
-> (forall a. (a -> a -> a) -> PreferAnnotation s a -> a)
-> (forall a. PreferAnnotation s a -> [a])
-> (forall a. PreferAnnotation s a -> Bool)
-> (forall a. PreferAnnotation s a -> Int)
-> (forall a. Eq a => a -> PreferAnnotation s a -> Bool)
-> (forall a. Ord a => PreferAnnotation s a -> a)
-> (forall a. Ord a => PreferAnnotation s a -> a)
-> (forall a. Num a => PreferAnnotation s a -> a)
-> (forall a. Num a => PreferAnnotation s a -> a)
-> Foldable (PreferAnnotation s)
forall a. Eq a => a -> PreferAnnotation s a -> Bool
forall a. Num a => PreferAnnotation s a -> a
forall a. Ord a => PreferAnnotation s a -> a
forall m. Monoid m => PreferAnnotation s m -> m
forall a. PreferAnnotation s a -> Bool
forall a. PreferAnnotation s a -> Int
forall a. PreferAnnotation s a -> [a]
forall a. (a -> a -> a) -> PreferAnnotation s a -> a
forall s a. Eq a => a -> PreferAnnotation s a -> Bool
forall s a. Num a => PreferAnnotation s a -> a
forall s a. Ord a => PreferAnnotation s a -> a
forall m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m
forall s m. Monoid m => PreferAnnotation s m -> m
forall s a. PreferAnnotation s a -> Bool
forall s a. PreferAnnotation s a -> Int
forall s a. PreferAnnotation s a -> [a]
forall b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b
forall a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b
forall s a. (a -> a -> a) -> PreferAnnotation s a -> a
forall s m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m
forall s b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b
forall s a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: PreferAnnotation s a -> a
$cproduct :: forall s a. Num a => PreferAnnotation s a -> a
sum :: PreferAnnotation s a -> a
$csum :: forall s a. Num a => PreferAnnotation s a -> a
minimum :: PreferAnnotation s a -> a
$cminimum :: forall s a. Ord a => PreferAnnotation s a -> a
maximum :: PreferAnnotation s a -> a
$cmaximum :: forall s a. Ord a => PreferAnnotation s a -> a
elem :: a -> PreferAnnotation s a -> Bool
$celem :: forall s a. Eq a => a -> PreferAnnotation s a -> Bool
length :: PreferAnnotation s a -> Int
$clength :: forall s a. PreferAnnotation s a -> Int
null :: PreferAnnotation s a -> Bool
$cnull :: forall s a. PreferAnnotation s a -> Bool
toList :: PreferAnnotation s a -> [a]
$ctoList :: forall s a. PreferAnnotation s a -> [a]
foldl1 :: (a -> a -> a) -> PreferAnnotation s a -> a
$cfoldl1 :: forall s a. (a -> a -> a) -> PreferAnnotation s a -> a
foldr1 :: (a -> a -> a) -> PreferAnnotation s a -> a
$cfoldr1 :: forall s a. (a -> a -> a) -> PreferAnnotation s a -> a
foldl' :: (b -> a -> b) -> b -> PreferAnnotation s a -> b
$cfoldl' :: forall s b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b
foldl :: (b -> a -> b) -> b -> PreferAnnotation s a -> b
$cfoldl :: forall s b a. (b -> a -> b) -> b -> PreferAnnotation s a -> b
foldr' :: (a -> b -> b) -> b -> PreferAnnotation s a -> b
$cfoldr' :: forall s a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b
foldr :: (a -> b -> b) -> b -> PreferAnnotation s a -> b
$cfoldr :: forall s a b. (a -> b -> b) -> b -> PreferAnnotation s a -> b
foldMap' :: (a -> m) -> PreferAnnotation s a -> m
$cfoldMap' :: forall s m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m
foldMap :: (a -> m) -> PreferAnnotation s a -> m
$cfoldMap :: forall s m a. Monoid m => (a -> m) -> PreferAnnotation s a -> m
fold :: PreferAnnotation s m -> m
$cfold :: forall s m. Monoid m => PreferAnnotation s m -> m
Foldable, a -> PreferAnnotation s b -> PreferAnnotation s a
(a -> b) -> PreferAnnotation s a -> PreferAnnotation s b
(forall a b.
 (a -> b) -> PreferAnnotation s a -> PreferAnnotation s b)
-> (forall a b. a -> PreferAnnotation s b -> PreferAnnotation s a)
-> Functor (PreferAnnotation s)
forall a b. a -> PreferAnnotation s b -> PreferAnnotation s a
forall a b.
(a -> b) -> PreferAnnotation s a -> PreferAnnotation s b
forall s a b. a -> PreferAnnotation s b -> PreferAnnotation s a
forall s a b.
(a -> b) -> PreferAnnotation s a -> PreferAnnotation s b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> PreferAnnotation s b -> PreferAnnotation s a
$c<$ :: forall s a b. a -> PreferAnnotation s b -> PreferAnnotation s a
fmap :: (a -> b) -> PreferAnnotation s a -> PreferAnnotation s b
$cfmap :: forall s a b.
(a -> b) -> PreferAnnotation s a -> PreferAnnotation s b
Functor, (forall x. PreferAnnotation s a -> Rep (PreferAnnotation s a) x)
-> (forall x. Rep (PreferAnnotation s a) x -> PreferAnnotation s a)
-> Generic (PreferAnnotation s a)
forall x. Rep (PreferAnnotation s a) x -> PreferAnnotation s a
forall x. PreferAnnotation s a -> Rep (PreferAnnotation s a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s a x. Rep (PreferAnnotation s a) x -> PreferAnnotation s a
forall s a x. PreferAnnotation s a -> Rep (PreferAnnotation s a) x
$cto :: forall s a x. Rep (PreferAnnotation s a) x -> PreferAnnotation s a
$cfrom :: forall s a x. PreferAnnotation s a -> Rep (PreferAnnotation s a) x
Generic, PreferAnnotation s a -> Q Exp
(PreferAnnotation s a -> Q Exp) -> Lift (PreferAnnotation s a)
forall t. (t -> Q Exp) -> Lift t
forall s a. (Lift s, Lift a) => PreferAnnotation s a -> Q Exp
lift :: PreferAnnotation s a -> Q Exp
$clift :: forall s a. (Lift s, Lift a) => PreferAnnotation s a -> Q Exp
Lift, PreferAnnotation s a -> ()
(PreferAnnotation s a -> ()) -> NFData (PreferAnnotation s a)
forall a. (a -> ()) -> NFData a
forall s a. (NFData s, NFData a) => PreferAnnotation s a -> ()
rnf :: PreferAnnotation s a -> ()
$crnf :: forall s a. (NFData s, NFData a) => PreferAnnotation s a -> ()
NFData, Eq (PreferAnnotation s a)
Eq (PreferAnnotation s a) =>
(PreferAnnotation s a -> PreferAnnotation s a -> Ordering)
-> (PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> (PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> (PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> (PreferAnnotation s a -> PreferAnnotation s a -> Bool)
-> (PreferAnnotation s a
    -> PreferAnnotation s a -> PreferAnnotation s a)
-> (PreferAnnotation s a
    -> PreferAnnotation s a -> PreferAnnotation s a)
-> Ord (PreferAnnotation s a)
PreferAnnotation s a -> PreferAnnotation s a -> Bool
PreferAnnotation s a -> PreferAnnotation s a -> Ordering
PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall s a. (Ord s, Ord a) => Eq (PreferAnnotation s a)
forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Ordering
forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
min :: PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
$cmin :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
max :: PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
$cmax :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a
-> PreferAnnotation s a -> PreferAnnotation s a
>= :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c>= :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
> :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c> :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
<= :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c<= :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
< :: PreferAnnotation s a -> PreferAnnotation s a -> Bool
$c< :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Bool
compare :: PreferAnnotation s a -> PreferAnnotation s a -> Ordering
$ccompare :: forall s a.
(Ord s, Ord a) =>
PreferAnnotation s a -> PreferAnnotation s a -> Ordering
$cp1Ord :: forall s a. (Ord s, Ord a) => Eq (PreferAnnotation s a)
Ord, Int -> PreferAnnotation s a -> ShowS
[PreferAnnotation s a] -> ShowS
PreferAnnotation s a -> String
(Int -> PreferAnnotation s a -> ShowS)
-> (PreferAnnotation s a -> String)
-> ([PreferAnnotation s a] -> ShowS)
-> Show (PreferAnnotation s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s a.
(Show s, Show a) =>
Int -> PreferAnnotation s a -> ShowS
forall s a. (Show s, Show a) => [PreferAnnotation s a] -> ShowS
forall s a. (Show s, Show a) => PreferAnnotation s a -> String
showList :: [PreferAnnotation s a] -> ShowS
$cshowList :: forall s a. (Show s, Show a) => [PreferAnnotation s a] -> ShowS
show :: PreferAnnotation s a -> String
$cshow :: forall s a. (Show s, Show a) => PreferAnnotation s a -> String
showsPrec :: Int -> PreferAnnotation s a -> ShowS
$cshowsPrec :: forall s a.
(Show s, Show a) =>
Int -> PreferAnnotation s a -> ShowS
Show, Functor (PreferAnnotation s)
Foldable (PreferAnnotation s)
(Functor (PreferAnnotation s), Foldable (PreferAnnotation s)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    PreferAnnotation s (f a) -> f (PreferAnnotation s a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> PreferAnnotation s a -> m (PreferAnnotation s b))
-> (forall (m :: * -> *) a.
    Monad m =>
    PreferAnnotation s (m a) -> m (PreferAnnotation s a))
-> Traversable (PreferAnnotation s)
(a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b)
forall s. Functor (PreferAnnotation s)
forall s. Foldable (PreferAnnotation s)
forall s (m :: * -> *) a.
Monad m =>
PreferAnnotation s (m a) -> m (PreferAnnotation s a)
forall s (f :: * -> *) a.
Applicative f =>
PreferAnnotation s (f a) -> f (PreferAnnotation s a)
forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreferAnnotation s a -> m (PreferAnnotation s b)
forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
PreferAnnotation s (m a) -> m (PreferAnnotation s a)
forall (f :: * -> *) a.
Applicative f =>
PreferAnnotation s (f a) -> f (PreferAnnotation s a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreferAnnotation s a -> m (PreferAnnotation s b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b)
sequence :: PreferAnnotation s (m a) -> m (PreferAnnotation s a)
$csequence :: forall s (m :: * -> *) a.
Monad m =>
PreferAnnotation s (m a) -> m (PreferAnnotation s a)
mapM :: (a -> m b) -> PreferAnnotation s a -> m (PreferAnnotation s b)
$cmapM :: forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PreferAnnotation s a -> m (PreferAnnotation s b)
sequenceA :: PreferAnnotation s (f a) -> f (PreferAnnotation s a)
$csequenceA :: forall s (f :: * -> *) a.
Applicative f =>
PreferAnnotation s (f a) -> f (PreferAnnotation s a)
traverse :: (a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b)
$ctraverse :: forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PreferAnnotation s a -> f (PreferAnnotation s b)
$cp2Traversable :: forall s. Foldable (PreferAnnotation s)
$cp1Traversable :: forall s. Functor (PreferAnnotation s)
Traversable)

instance Bifunctor PreferAnnotation where
    first :: (a -> b) -> PreferAnnotation a c -> PreferAnnotation b c
first _  PreferFromSource      = PreferAnnotation b c
forall s a. PreferAnnotation s a
PreferFromSource
    first f :: a -> b
f (PreferFromWith e :: Expr a c
e    ) = Expr b c -> PreferAnnotation b c
forall s a. Expr s a -> PreferAnnotation s a
PreferFromWith ((a -> b) -> Expr a c -> Expr b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
f Expr a c
e)
    first _  PreferFromCompletion  = PreferAnnotation b c
forall s a. PreferAnnotation s a
PreferFromCompletion

    second :: (b -> c) -> PreferAnnotation a b -> PreferAnnotation a c
second = (b -> c) -> PreferAnnotation a b -> PreferAnnotation a c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

{-| Syntax tree for expressions

    The @s@ type parameter is used to track the presence or absence of `Src`
    spans:

    * If @s = `Src`@ then the code may contains `Src` spans (either in a `Noted`
      constructor or inline within another constructor, like `Let`)
    * If @s = `Void`@ then the code has no `Src` spans

    The @a@ type parameter is used to track the presence or absence of imports

    * If @a = `Import`@ then the code may contain unresolved `Import`s
    * If @a = `Void`@ then the code has no `Import`s
-}
data Expr s a
    -- | > Const c                                  ~  c
    = Const Const
    -- | > Var (V x 0)                              ~  x
    --   > Var (V x n)                              ~  x@n
    | Var Var
    -- | > Lam x     A b                            ~  λ(x : A) -> b
    | Lam Text (Expr s a) (Expr s a)
    -- | > Pi "_" A B                               ~        A  -> B
    --   > Pi x   A B                               ~  ∀(x : A) -> B
    | Pi  Text (Expr s a) (Expr s a)
    -- | > App f a                                  ~  f a
    | App (Expr 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 'Note' around @'Let' "y" …@ in the second
    -- example.
    --
    -- See 'MultiLet' for a representation of let-blocks that mirrors the
    -- source code more closely.
    | Let (Binding s a) (Expr s a)
    -- | > Annot x t                                ~  x : t
    | Annot (Expr s a) (Expr s a)
    -- | > Bool                                     ~  Bool
    | Bool
    -- | > BoolLit b                                ~  b
    | BoolLit Bool
    -- | > BoolAnd x y                              ~  x && y
    | BoolAnd (Expr s a) (Expr s a)
    -- | > BoolOr  x y                              ~  x || y
    | BoolOr  (Expr s a) (Expr s a)
    -- | > BoolEQ  x y                              ~  x == y
    | BoolEQ  (Expr s a) (Expr s a)
    -- | > BoolNE  x y                              ~  x != y
    | BoolNE  (Expr s a) (Expr s a)
    -- | > BoolIf x y z                             ~  if x then y else z
    | BoolIf (Expr s a) (Expr s a) (Expr s a)
    -- | > Natural                                  ~  Natural
    | Natural
    -- | > NaturalLit n                             ~  n
    | NaturalLit Natural
    -- | > NaturalFold                              ~  Natural/fold
    | NaturalFold
    -- | > NaturalBuild                             ~  Natural/build
    | NaturalBuild
    -- | > NaturalIsZero                            ~  Natural/isZero
    | NaturalIsZero
    -- | > NaturalEven                              ~  Natural/even
    | NaturalEven
    -- | > NaturalOdd                               ~  Natural/odd
    | NaturalOdd
    -- | > NaturalToInteger                         ~  Natural/toInteger
    | NaturalToInteger
    -- | > NaturalShow                              ~  Natural/show
    | NaturalShow
    -- | > NaturalSubtract                          ~  Natural/subtract
    | NaturalSubtract
    -- | > NaturalPlus x y                          ~  x + y
    | NaturalPlus (Expr s a) (Expr s a)
    -- | > NaturalTimes x y                         ~  x * y
    | NaturalTimes (Expr s a) (Expr s a)
    -- | > Integer                                  ~  Integer
    | Integer
    -- | > IntegerLit n                             ~  ±n
    | IntegerLit Integer
    -- | > IntegerClamp                               ~  Integer/clamp
    | IntegerClamp
    -- | > IntegerNegate                              ~  Integer/negate
    | IntegerNegate
    -- | > IntegerShow                              ~  Integer/show
    | IntegerShow
    -- | > IntegerToDouble                          ~  Integer/toDouble
    | IntegerToDouble
    -- | > Double                                   ~  Double
    | Double
    -- | > DoubleLit n                              ~  n
    | DoubleLit DhallDouble
    -- | > DoubleShow                               ~  Double/show
    | DoubleShow
    -- | > Text                                     ~  Text
    | Text
    -- | > TextLit (Chunks [(t1, e1), (t2, e2)] t3) ~  "t1${e1}t2${e2}t3"
    | TextLit (Chunks s a)
    -- | > TextAppend x y                           ~  x ++ y
    | TextAppend (Expr s a) (Expr s a)
    -- | > TextShow                                 ~  Text/show
    | TextShow
    -- | > List                                     ~  List
    | List
    -- | > ListLit (Just t ) []                     ~  [] : t
    --   > ListLit  Nothing  [x, y, z]              ~  [x, y, z]
    --
    --   Invariant: A non-empty list literal is always represented as
    --   @ListLit Nothing xs@.
    --
    --   When an annotated, non-empty list literal is parsed, it is represented
    --   as
    --
    --   > Annot (ListLit Nothing [x, y, z]) t      ~ [x, y, z] : t

    -- Eventually we should have separate constructors for empty and non-empty
    -- list literals. For now it's easier to check the invariant in @infer@.
    -- See https://github.com/dhall-lang/dhall-haskell/issues/1359#issuecomment-537087234.
    | ListLit (Maybe (Expr s a)) (Seq (Expr s a))
    -- | > ListAppend x y                           ~  x # y
    | ListAppend (Expr s a) (Expr s a)
    -- | > ListBuild                                ~  List/build
    | ListBuild
    -- | > ListFold                                 ~  List/fold
    | ListFold
    -- | > ListLength                               ~  List/length
    | ListLength
    -- | > ListHead                                 ~  List/head
    | ListHead
    -- | > ListLast                                 ~  List/last
    | ListLast
    -- | > ListIndexed                              ~  List/indexed
    | ListIndexed
    -- | > ListReverse                              ~  List/reverse
    | ListReverse
    -- | > Optional                                 ~  Optional
    | Optional
    -- | > Some e                                   ~  Some e
    | Some (Expr s a)
    -- | > None                                     ~  None
    | None
    -- | > OptionalFold                             ~  Optional/fold
    | OptionalFold
    -- | > OptionalBuild                            ~  Optional/build
    | OptionalBuild
    -- | > Record       [(k1, t1), (k2, t2)]        ~  { k1 : t1, k2 : t1 }
    | Record    (Map Text (Expr s a))
    -- | > RecordLit    [(k1, v1), (k2, v2)]        ~  { k1 = v1, k2 = v2 }
    | RecordLit (Map Text (Expr s a))
    -- | > Union        [(k1, Just t1), (k2, Nothing)] ~  < k1 : t1 | k2 >
    | Union     (Map Text (Maybe (Expr s a)))
    -- | > Combine Nothing x y                      ~  x ∧ y
    --
    -- The first field is a `Just` when the `Combine` operator is introduced
    -- as a result of desugaring duplicate record fields:
    --
    --   > RecordLit [ (k, Combine (Just k) x y) ]  ~ { k = x, k = y }
    | Combine (Maybe Text) (Expr s a) (Expr s a)
    -- | > CombineTypes x y                         ~  x ⩓ y
    | CombineTypes (Expr s a) (Expr s a)
    -- | > Prefer False x y                         ~  x ⫽ y
    --
    -- The first field is a `True` when the `Prefer` operator is introduced as a
    -- result of desugaring a @with@ expression
    | Prefer (PreferAnnotation s a) (Expr s a) (Expr s a)
    -- | > RecordCompletion x y                     ~  x::y
    | RecordCompletion (Expr s a) (Expr s a)
    -- | > Merge x y (Just t )                      ~  merge x y : t
    --   > Merge x y  Nothing                       ~  merge x y
    | Merge (Expr s a) (Expr s a) (Maybe (Expr s a))
    -- | > ToMap x (Just t)                         ~  toMap x : t
    --   > ToMap x  Nothing                         ~  toMap x
    | ToMap (Expr s a) (Maybe (Expr s a))
    -- | > Field e x                                ~  e.x
    | Field (Expr s a) Text
    -- | > Project e (Left xs)                      ~  e.{ xs }
    --   > Project e (Right t)                      ~  e.(t)
    | Project (Expr s a) (Either (Set Text) (Expr s a))
    -- | > Assert e                                 ~  assert : e
    | Assert (Expr s a)
    -- | > Equivalent x y                           ~  x ≡ y
    | Equivalent (Expr s a) (Expr s a)
    -- | > With x y                                 ~  x with y
    | With (Expr s a) (NonEmpty Text) (Expr s a)
    -- | > Note s x                                 ~  e
    | Note s (Expr s a)
    -- | > ImportAlt                                ~  e1 ? e2
    | ImportAlt (Expr s a) (Expr s a)
    -- | > Embed import                             ~  import
    | Embed a
    deriving (Expr s a -> Bool
(a -> m) -> Expr s a -> m
(a -> b -> b) -> b -> Expr s a -> b
(forall m. Monoid m => Expr s m -> m)
-> (forall m a. Monoid m => (a -> m) -> Expr s a -> m)
-> (forall m a. Monoid m => (a -> m) -> Expr s a -> m)
-> (forall a b. (a -> b -> b) -> b -> Expr s a -> b)
-> (forall a b. (a -> b -> b) -> b -> Expr s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Expr s a -> b)
-> (forall b a. (b -> a -> b) -> b -> Expr s a -> b)
-> (forall a. (a -> a -> a) -> Expr s a -> a)
-> (forall a. (a -> a -> a) -> Expr s a -> a)
-> (forall a. Expr s a -> [a])
-> (forall a. Expr s a -> Bool)
-> (forall a. Expr s a -> Int)
-> (forall a. Eq a => a -> Expr s a -> Bool)
-> (forall a. Ord a => Expr s a -> a)
-> (forall a. Ord a => Expr s a -> a)
-> (forall a. Num a => Expr s a -> a)
-> (forall a. Num a => Expr s a -> a)
-> Foldable (Expr s)
forall a. Eq a => a -> Expr s a -> Bool
forall a. Num a => Expr s a -> a
forall a. Ord a => Expr s a -> a
forall m. Monoid m => Expr s m -> m
forall a. Expr s a -> Bool
forall a. Expr s a -> Int
forall a. Expr s a -> [a]
forall a. (a -> a -> a) -> Expr s a -> a
forall s a. Eq a => a -> Expr s a -> Bool
forall s a. Num a => Expr s a -> a
forall s a. Ord a => Expr s a -> a
forall m a. Monoid m => (a -> m) -> Expr s a -> m
forall s m. Monoid m => Expr s m -> m
forall s a. Expr s a -> Bool
forall s a. Expr s a -> Int
forall s a. Expr s a -> [a]
forall b a. (b -> a -> b) -> b -> Expr s a -> b
forall a b. (a -> b -> b) -> b -> Expr s a -> b
forall s a. (a -> a -> a) -> Expr s a -> a
forall s m a. Monoid m => (a -> m) -> Expr s a -> m
forall s b a. (b -> a -> b) -> b -> Expr s a -> b
forall s a b. (a -> b -> b) -> b -> Expr s a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Expr s a -> a
$cproduct :: forall s a. Num a => Expr s a -> a
sum :: Expr s a -> a
$csum :: forall s a. Num a => Expr s a -> a
minimum :: Expr s a -> a
$cminimum :: forall s a. Ord a => Expr s a -> a
maximum :: Expr s a -> a
$cmaximum :: forall s a. Ord a => Expr s a -> a
elem :: a -> Expr s a -> Bool
$celem :: forall s a. Eq a => a -> Expr s a -> Bool
length :: Expr s a -> Int
$clength :: forall s a. Expr s a -> Int
null :: Expr s a -> Bool
$cnull :: forall s a. Expr s a -> Bool
toList :: Expr s a -> [a]
$ctoList :: forall s a. Expr s a -> [a]
foldl1 :: (a -> a -> a) -> Expr s a -> a
$cfoldl1 :: forall s a. (a -> a -> a) -> Expr s a -> a
foldr1 :: (a -> a -> a) -> Expr s a -> a
$cfoldr1 :: forall s a. (a -> a -> a) -> Expr s a -> a
foldl' :: (b -> a -> b) -> b -> Expr s a -> b
$cfoldl' :: forall s b a. (b -> a -> b) -> b -> Expr s a -> b
foldl :: (b -> a -> b) -> b -> Expr s a -> b
$cfoldl :: forall s b a. (b -> a -> b) -> b -> Expr s a -> b
foldr' :: (a -> b -> b) -> b -> Expr s a -> b
$cfoldr' :: forall s a b. (a -> b -> b) -> b -> Expr s a -> b
foldr :: (a -> b -> b) -> b -> Expr s a -> b
$cfoldr :: forall s a b. (a -> b -> b) -> b -> Expr s a -> b
foldMap' :: (a -> m) -> Expr s a -> m
$cfoldMap' :: forall s m a. Monoid m => (a -> m) -> Expr s a -> m
foldMap :: (a -> m) -> Expr s a -> m
$cfoldMap :: forall s m a. Monoid m => (a -> m) -> Expr s a -> m
fold :: Expr s m -> m
$cfold :: forall s m. Monoid m => Expr s m -> m
Foldable, (forall x. Expr s a -> Rep (Expr s a) x)
-> (forall x. Rep (Expr s a) x -> Expr s a) -> Generic (Expr s a)
forall x. Rep (Expr s a) x -> Expr s a
forall x. Expr s a -> Rep (Expr s a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s a x. Rep (Expr s a) x -> Expr s a
forall s a x. Expr s a -> Rep (Expr s a) x
$cto :: forall s a x. Rep (Expr s a) x -> Expr s a
$cfrom :: forall s a x. Expr s a -> Rep (Expr s a) x
Generic, Functor (Expr s)
Foldable (Expr s)
(Functor (Expr s), Foldable (Expr s)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Expr s a -> f (Expr s b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Expr s (f a) -> f (Expr s a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Expr s a -> m (Expr s b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Expr s (m a) -> m (Expr s a))
-> Traversable (Expr s)
(a -> f b) -> Expr s a -> f (Expr s b)
forall s. Functor (Expr s)
forall s. Foldable (Expr s)
forall s (m :: * -> *) a. Monad m => Expr s (m a) -> m (Expr s a)
forall s (f :: * -> *) a.
Applicative f =>
Expr s (f a) -> f (Expr s a)
forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Expr s a -> m (Expr s b)
forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Expr s a -> f (Expr s b)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Expr s (m a) -> m (Expr s a)
forall (f :: * -> *) a.
Applicative f =>
Expr s (f a) -> f (Expr s a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Expr s a -> m (Expr s b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Expr s a -> f (Expr s b)
sequence :: Expr s (m a) -> m (Expr s a)
$csequence :: forall s (m :: * -> *) a. Monad m => Expr s (m a) -> m (Expr s a)
mapM :: (a -> m b) -> Expr s a -> m (Expr s b)
$cmapM :: forall s (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Expr s a -> m (Expr s b)
sequenceA :: Expr s (f a) -> f (Expr s a)
$csequenceA :: forall s (f :: * -> *) a.
Applicative f =>
Expr s (f a) -> f (Expr s a)
traverse :: (a -> f b) -> Expr s a -> f (Expr s b)
$ctraverse :: forall s (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Expr s a -> f (Expr s b)
$cp2Traversable :: forall s. Foldable (Expr s)
$cp1Traversable :: forall s. Functor (Expr s)
Traversable, Int -> Expr s a -> ShowS
[Expr s a] -> ShowS
Expr s a -> String
(Int -> Expr s a -> ShowS)
-> (Expr s a -> String) -> ([Expr s a] -> ShowS) -> Show (Expr s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s a. (Show s, Show a) => Int -> Expr s a -> ShowS
forall s a. (Show s, Show a) => [Expr s a] -> ShowS
forall s a. (Show s, Show a) => Expr s a -> String
showList :: [Expr s a] -> ShowS
$cshowList :: forall s a. (Show s, Show a) => [Expr s a] -> ShowS
show :: Expr s a -> String
$cshow :: forall s a. (Show s, Show a) => Expr s a -> String
showsPrec :: Int -> Expr s a -> ShowS
$cshowsPrec :: forall s a. (Show s, Show a) => Int -> Expr s a -> ShowS
Show, Typeable (Expr s a)
DataType
Constr
Typeable (Expr s a) =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Expr s a -> c (Expr s a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Expr s a))
-> (Expr s a -> Constr)
-> (Expr s a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Expr s a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Expr s a)))
-> ((forall b. Data b => b -> b) -> Expr s a -> Expr s a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Expr s a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Expr s a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Expr s a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Expr s a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a))
-> Data (Expr s a)
Expr s a -> DataType
Expr s a -> Constr
(forall b. Data b => b -> b) -> Expr s a -> Expr s a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr s a -> c (Expr s a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr s a)
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr s a))
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Expr s a -> u
forall u. (forall d. Data d => d -> u) -> Expr s a -> [u]
forall s a. (Data s, Data a) => Typeable (Expr s a)
forall s a. (Data s, Data a) => Expr s a -> DataType
forall s a. (Data s, Data a) => Expr s a -> Constr
forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Expr s a -> Expr s a
forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Expr s a -> u
forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Expr s a -> [u]
forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr s a)
forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr s a -> c (Expr s a)
forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr s a))
forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr s a))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr s a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr s a -> c (Expr s a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr s a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr s a))
$cEmbed :: Constr
$cImportAlt :: Constr
$cNote :: Constr
$cWith :: Constr
$cEquivalent :: Constr
$cAssert :: Constr
$cProject :: Constr
$cField :: Constr
$cToMap :: Constr
$cMerge :: Constr
$cRecordCompletion :: Constr
$cPrefer :: Constr
$cCombineTypes :: Constr
$cCombine :: Constr
$cUnion :: Constr
$cRecordLit :: Constr
$cRecord :: Constr
$cOptionalBuild :: Constr
$cOptionalFold :: Constr
$cNone :: Constr
$cSome :: Constr
$cOptional :: Constr
$cListReverse :: Constr
$cListIndexed :: Constr
$cListLast :: Constr
$cListHead :: Constr
$cListLength :: Constr
$cListFold :: Constr
$cListBuild :: Constr
$cListAppend :: Constr
$cListLit :: Constr
$cList :: Constr
$cTextShow :: Constr
$cTextAppend :: Constr
$cTextLit :: Constr
$cText :: Constr
$cDoubleShow :: Constr
$cDoubleLit :: Constr
$cDouble :: Constr
$cIntegerToDouble :: Constr
$cIntegerShow :: Constr
$cIntegerNegate :: Constr
$cIntegerClamp :: Constr
$cIntegerLit :: Constr
$cInteger :: Constr
$cNaturalTimes :: Constr
$cNaturalPlus :: Constr
$cNaturalSubtract :: Constr
$cNaturalShow :: Constr
$cNaturalToInteger :: Constr
$cNaturalOdd :: Constr
$cNaturalEven :: Constr
$cNaturalIsZero :: Constr
$cNaturalBuild :: Constr
$cNaturalFold :: Constr
$cNaturalLit :: Constr
$cNatural :: Constr
$cBoolIf :: Constr
$cBoolNE :: Constr
$cBoolEQ :: Constr
$cBoolOr :: Constr
$cBoolAnd :: Constr
$cBoolLit :: Constr
$cBool :: Constr
$cAnnot :: Constr
$cLet :: Constr
$cApp :: Constr
$cPi :: Constr
$cLam :: Constr
$cVar :: Constr
$cConst :: Constr
$tExpr :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
$cgmapMo :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
gmapMp :: (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
$cgmapMp :: forall s a (m :: * -> *).
(Data s, Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
gmapM :: (forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
$cgmapM :: forall s a (m :: * -> *).
(Data s, Data a, Monad m) =>
(forall d. Data d => d -> m d) -> Expr s a -> m (Expr s a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Expr s a -> u
$cgmapQi :: forall s a u.
(Data s, Data a) =>
Int -> (forall d. Data d => d -> u) -> Expr s a -> u
gmapQ :: (forall d. Data d => d -> u) -> Expr s a -> [u]
$cgmapQ :: forall s a u.
(Data s, Data a) =>
(forall d. Data d => d -> u) -> Expr s a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
$cgmapQr :: forall s a r r'.
(Data s, Data a) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
$cgmapQl :: forall s a r r'.
(Data s, Data a) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Expr s a -> r
gmapT :: (forall b. Data b => b -> b) -> Expr s a -> Expr s a
$cgmapT :: forall s a.
(Data s, Data a) =>
(forall b. Data b => b -> b) -> Expr s a -> Expr s a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr s a))
$cdataCast2 :: forall s a (t :: * -> * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Expr s a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Expr s a))
$cdataCast1 :: forall s a (t :: * -> *) (c :: * -> *).
(Data s, Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Expr s a))
dataTypeOf :: Expr s a -> DataType
$cdataTypeOf :: forall s a. (Data s, Data a) => Expr s a -> DataType
toConstr :: Expr s a -> Constr
$ctoConstr :: forall s a. (Data s, Data a) => Expr s a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr s a)
$cgunfold :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Expr s a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr s a -> c (Expr s a)
$cgfoldl :: forall s a (c :: * -> *).
(Data s, Data a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Expr s a -> c (Expr s a)
$cp1Data :: forall s a. (Data s, Data a) => Typeable (Expr s a)
Data, Expr s a -> Q Exp
(Expr s a -> Q Exp) -> Lift (Expr s a)
forall t. (t -> Q Exp) -> Lift t
forall s a. (Lift s, Lift a) => Expr s a -> Q Exp
lift :: Expr s a -> Q Exp
$clift :: forall s a. (Lift s, Lift a) => Expr s a -> Q Exp
Lift, Expr s a -> ()
(Expr s a -> ()) -> NFData (Expr s a)
forall a. (a -> ()) -> NFData a
forall s a. (NFData s, NFData a) => Expr s a -> ()
rnf :: Expr s a -> ()
$crnf :: forall s a. (NFData s, NFData a) => Expr s a -> ()
NFData)
-- NB: If you add a constructor to Expr, please also update the Arbitrary
-- instance in Dhall.Test.QuickCheck.

-- | This instance encodes what the Dhall standard calls an \"exact match\"
-- between two expressions.
--
-- Note that
--
-- >>> nan = DhallDouble (0/0)
-- >>> DoubleLit nan == DoubleLit nan
-- True
deriving instance (Eq s, Eq a) => Eq (Expr s a)

-- | Note that this 'Ord' instance inherits `DhallDouble`'s defects.
deriving instance (Ord s, Ord a) => Ord (Expr s a)

-- This instance is hand-written due to the fact that deriving
-- it does not give us an INLINABLE pragma. We annotate this fmap
-- implementation with this pragma below to allow GHC to, possibly,
-- inline the implementation for performance improvements.
instance Functor (Expr s) where
  fmap :: (a -> b) -> Expr s a -> Expr s b
fmap f :: a -> b
f (Embed a :: a
a) = b -> Expr s b
forall s a. a -> Expr s a
Embed (a -> b
f a
a)
  fmap f :: a -> b
f (Let b :: Binding s a
b e2 :: Expr s a
e2) = Binding s b -> Expr s b -> Expr s b
forall s a. Binding s a -> Expr s a -> Expr s a
Let ((a -> b) -> Binding s a -> Binding s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Binding s a
b) ((a -> b) -> Expr s a -> Expr s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Expr s a
e2)
  fmap f :: a -> b
f (Note s :: s
s e1 :: Expr s a
e1) = s -> Expr s b -> Expr s b
forall s a. s -> Expr s a -> Expr s a
Note s
s ((a -> b) -> Expr s a -> Expr s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Expr s a
e1)
  fmap f :: a -> b
f expression :: Expr s a
expression = ASetter (Expr s a) (Expr s b) (Expr s a) (Expr s b)
-> (Expr s a -> Expr s b) -> Expr s a -> Expr s b
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
Lens.over ASetter (Expr s a) (Expr s b) (Expr s a) (Expr s b)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions ((a -> b) -> Expr s a -> Expr s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) Expr s a
expression
  {-# INLINABLE fmap #-}

instance Applicative (Expr s) where
    pure :: a -> Expr s a
pure = a -> Expr s a
forall s a. a -> Expr s a
Embed

    <*> :: Expr s (a -> b) -> Expr s a -> Expr s b
(<*>) = Expr s (a -> b) -> Expr s a -> Expr s b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
Control.Monad.ap

instance Monad (Expr s) where
    return :: a -> Expr s a
return = a -> Expr s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

    Embed a :: a
a    >>= :: Expr s a -> (a -> Expr s b) -> Expr s b
>>= k :: a -> Expr s b
k = a -> Expr s b
k a
a
    Let a :: Binding s a
a b :: Expr s a
b    >>= k :: a -> Expr s b
k = Binding s b -> Expr s b -> Expr s b
forall s a. Binding s a -> Expr s a -> Expr s a
Let (Binding s a -> Binding s b
adapt0 Binding s a
a) (Expr s a
b Expr s a -> (a -> Expr s b) -> Expr s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Expr s b
k)
      where
        adapt0 :: Binding s a -> Binding s b
adapt0 (Binding src0 :: Maybe s
src0 c :: Text
c src1 :: Maybe s
src1 d :: Maybe (Maybe s, Expr s a)
d src2 :: Maybe s
src2 e :: Expr s a
e) =
            Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s b)
-> Maybe s
-> Expr s b
-> Binding s b
forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding Maybe s
src0 Text
c Maybe s
src1 (((Maybe s, Expr s a) -> (Maybe s, Expr s b))
-> Maybe (Maybe s, Expr s a) -> Maybe (Maybe s, Expr s b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe s, Expr s a) -> (Maybe s, Expr s b)
forall a. (a, Expr s a) -> (a, Expr s b)
adapt1 Maybe (Maybe s, Expr s a)
d) Maybe s
src2 (Expr s a
e Expr s a -> (a -> Expr s b) -> Expr s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Expr s b
k)

        adapt1 :: (a, Expr s a) -> (a, Expr s b)
adapt1 (src3 :: a
src3, f :: Expr s a
f) = (a
src3, Expr s a
f Expr s a -> (a -> Expr s b) -> Expr s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Expr s b
k)
    Note a :: s
a b :: Expr s a
b   >>= k :: a -> Expr s b
k = s -> Expr s b -> Expr s b
forall s a. s -> Expr s a -> Expr s a
Note s
a (Expr s a
b Expr s a -> (a -> Expr s b) -> Expr s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Expr s b
k)
    expression :: Expr s a
expression >>= k :: a -> Expr s b
k = ASetter (Expr s a) (Expr s b) (Expr s a) (Expr s b)
-> (Expr s a -> Expr s b) -> Expr s a -> Expr s b
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
Lens.over ASetter (Expr s a) (Expr s b) (Expr s a) (Expr s b)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions (Expr s a -> (a -> Expr s b) -> Expr s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Expr s b
k) Expr s a
expression

instance Bifunctor Expr where
    first :: (a -> b) -> Expr a c -> Expr b c
first k :: a -> b
k (Note a :: a
a b :: Expr a c
b  ) = b -> Expr b c -> Expr b c
forall s a. s -> Expr s a -> Expr s a
Note (a -> b
k a
a) ((a -> b) -> Expr a c -> Expr b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
b)
    first _ (Embed a :: c
a   ) = c -> Expr b c
forall s a. a -> Expr s a
Embed c
a
    first k :: a -> b
k (Let a :: Binding a c
a b :: Expr a c
b   ) = Binding b c -> Expr b c -> Expr b c
forall s a. Binding s a -> Expr s a -> Expr s a
Let ((a -> b) -> Binding a c -> Binding b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Binding a c
a) ((a -> b) -> Expr a c -> Expr b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k Expr a c
b)
    first k :: a -> b
k  expression :: Expr a c
expression  = ASetter (Expr a c) (Expr b c) (Expr a c) (Expr b c)
-> (Expr a c -> Expr b c) -> Expr a c -> Expr b c
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
Lens.over ASetter (Expr a c) (Expr b c) (Expr a c) (Expr b c)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions ((a -> b) -> Expr a c -> Expr b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first a -> b
k) Expr a c
expression

    second :: (b -> c) -> Expr a b -> Expr a c
second = (b -> c) -> Expr a b -> Expr a c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap

instance IsString (Expr s a) where
    fromString :: String -> Expr s a
fromString str :: String
str = Var -> Expr s a
forall s a. Var -> Expr s a
Var (String -> Var
forall a. IsString a => String -> a
fromString String
str)

-- | Generates a syntactically valid Dhall program
instance Pretty a => Pretty (Expr s a) where
    pretty :: Expr s a -> Doc ann
pretty = Doc Ann -> Doc ann
forall ann xxx. Doc ann -> Doc xxx
Pretty.unAnnotate (Doc Ann -> Doc ann)
-> (Expr s a -> Doc Ann) -> Expr s a -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr s a -> Doc Ann
forall a s. Pretty a => Expr s a -> Doc Ann
prettyExpr

{-
Instead of converting explicitly between 'Expr's and 'MultiLet', it might
be nicer to use a pattern synonym:

> pattern MultiLet' :: NonEmpty (Binding s a) -> Expr s a -> Expr s a
> pattern MultiLet' as b <- (multiLetFromExpr -> Just (MultiLet as b)) where
>   MultiLet' as b = wrapInLets as b
>
> multiLetFromExpr :: Expr s a -> Maybe (MultiLet s a)
> multiLetFromExpr = \case
>     Let x mA a b -> Just (multiLet x mA a b)
>     _ -> Nothing

This works in principle, but GHC as of v8.8.1 doesn't handle it well:
https://gitlab.haskell.org/ghc/ghc/issues/17096

This should be fixed by GHC-8.10, so it might be worth revisiting then.
-}

{-| Generate a 'MultiLet' from the contents of a 'Let'.

    In the resulting @'MultiLet' bs e@, @e@ is guaranteed not to be a 'Let',
    but it might be a @('Note' … ('Let' …))@.

    Given parser output, 'multiLet' consolidates @let@s that formed a
    let-block in the original source.
-}
multiLet :: Binding s a -> Expr s a -> MultiLet s a
multiLet :: Binding s a -> Expr s a -> MultiLet s a
multiLet b0 :: Binding s a
b0 = \case
    Let b1 :: Binding s a
b1 e1 :: Expr s a
e1 ->
        let MultiLet bs :: NonEmpty (Binding s a)
bs e :: Expr s a
e = Binding s a -> Expr s a -> MultiLet s a
forall s a. Binding s a -> Expr s a -> MultiLet s a
multiLet Binding s a
b1 Expr s a
e1
        in  NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (Binding s a -> NonEmpty (Binding s a) -> NonEmpty (Binding s a)
forall a. a -> NonEmpty a -> NonEmpty a
NonEmpty.cons Binding s a
b0 NonEmpty (Binding s a)
bs) Expr s a
e
    e :: Expr s a
e -> NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (Binding s a
b0 Binding s a -> [Binding s a] -> NonEmpty (Binding s a)
forall a. a -> [a] -> NonEmpty a
:| []) Expr s a
e

{-| 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
-}
wrapInLets :: Foldable f => f (Binding s a) -> Expr s a -> Expr s a
wrapInLets :: f (Binding s a) -> Expr s a -> Expr s a
wrapInLets bs :: f (Binding s a)
bs e :: Expr s a
e = (Binding s a -> Expr s a -> Expr s a)
-> Expr s a -> f (Binding s a) -> Expr s a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Binding s a -> Expr s a -> Expr s a
forall s a. Binding s a -> Expr s a -> Expr s a
Let Expr s a
e f (Binding s a)
bs

{-| This type represents 1 or more nested `Let` bindings that have been
    coalesced together for ease of manipulation
-}
data MultiLet s a = MultiLet (NonEmpty (Binding s a)) (Expr s a)

-- | A traversal over the immediate sub-expressions of an expression.
subExpressions
    :: Applicative f => (Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a)
subExpressions :: (Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a)
subExpressions _ (Embed a :: a
a) = Expr s a -> f (Expr s a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Expr s a
forall s a. a -> Expr s a
Embed a
a)
subExpressions f :: Expr s a -> f (Expr s a)
f (Note a :: s
a b :: Expr s a
b) = s -> Expr s a -> Expr s a
forall s a. s -> Expr s a -> Expr s a
Note s
a (Expr s a -> Expr s a) -> f (Expr s a) -> f (Expr s a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr s a)
f Expr s a
b
subExpressions f :: Expr s a -> f (Expr s a)
f (Let a :: Binding s a
a b :: Expr s a
b) = Binding s a -> Expr s a -> Expr s a
forall s a. Binding s a -> Expr s a -> Expr s a
Let (Binding s a -> Expr s a -> Expr s a)
-> f (Binding s a) -> f (Expr s a -> Expr s a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr s a -> f (Expr s a)) -> Binding s a -> f (Binding s a)
forall (f :: * -> *) s a b.
Applicative f =>
(Expr s a -> f (Expr s b)) -> Binding s a -> f (Binding s b)
bindingExprs Expr s a -> f (Expr s a)
f Binding s a
a f (Expr s a -> Expr s a) -> f (Expr s a) -> f (Expr s a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr s a)
f Expr s a
b
subExpressions f :: Expr s a -> f (Expr s a)
f expression :: Expr s a
expression = (Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions Expr s a -> f (Expr s a)
f Expr s a
expression
{-# INLINABLE subExpressions #-}

{-| An internal utility used to implement transformations that require changing
    one of the type variables of the `Expr` type

    This utility only works because the implementation is partial, not
    handling the `Let`, `Note`, or `Embed` cases, which need to be handled by
    the caller.
-}
unsafeSubExpressions
    :: Applicative f => (Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions :: (Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions _ (Const c :: Const
c) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Const -> Expr t b
forall s a. Const -> Expr s a
Const Const
c)
unsafeSubExpressions _ (Var v :: Var
v) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Var -> Expr t b
forall s a. Var -> Expr s a
Var Var
v)
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Lam a :: Text
a b :: Expr s a
b c :: Expr s a
c) = Text -> Expr t b -> Expr t b -> Expr t b
forall s a. Text -> Expr s a -> Expr s a -> Expr s a
Lam Text
a (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Pi a :: Text
a b :: Expr s a
b c :: Expr s a
c) = Text -> Expr t b -> Expr t b -> Expr t b
forall s a. Text -> Expr s a -> Expr s a -> Expr s a
Pi Text
a (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (App a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
App (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Annot a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
Annot (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions _ Bool = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Bool
unsafeSubExpressions _ (BoolLit b :: Bool
b) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> Expr t b
forall s a. Bool -> Expr s a
BoolLit Bool
b)
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (BoolAnd a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
BoolAnd (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (BoolOr a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
BoolOr (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (BoolEQ a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
BoolEQ (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (BoolNE a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
BoolNE (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (BoolIf a :: Expr s a
a b :: Expr s a
b c :: Expr s a
c) = Expr t b -> Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a -> Expr s a
BoolIf (Expr t b -> Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
unsafeSubExpressions _ Natural = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Natural
unsafeSubExpressions _ (NaturalLit n :: Natural
n) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Natural -> Expr t b
forall s a. Natural -> Expr s a
NaturalLit Natural
n)
unsafeSubExpressions _ NaturalFold = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalFold
unsafeSubExpressions _ NaturalBuild = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalBuild
unsafeSubExpressions _ NaturalIsZero = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalIsZero
unsafeSubExpressions _ NaturalEven = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalEven
unsafeSubExpressions _ NaturalOdd = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalOdd
unsafeSubExpressions _ NaturalToInteger = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalToInteger
unsafeSubExpressions _ NaturalShow = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalShow
unsafeSubExpressions _ NaturalSubtract = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
NaturalSubtract
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (NaturalPlus a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
NaturalPlus (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (NaturalTimes a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
NaturalTimes (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions _ Integer = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Integer
unsafeSubExpressions _ (IntegerLit n :: Integer
n) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> Expr t b
forall s a. Integer -> Expr s a
IntegerLit Integer
n)
unsafeSubExpressions _ IntegerClamp = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
IntegerClamp
unsafeSubExpressions _ IntegerNegate = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
IntegerNegate
unsafeSubExpressions _ IntegerShow = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
IntegerShow
unsafeSubExpressions _ IntegerToDouble = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
IntegerToDouble
unsafeSubExpressions _ Double = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Double
unsafeSubExpressions _ (DoubleLit n :: DhallDouble
n) = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DhallDouble -> Expr t b
forall s a. DhallDouble -> Expr s a
DoubleLit DhallDouble
n)
unsafeSubExpressions _ DoubleShow = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
DoubleShow
unsafeSubExpressions _ Text = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Text
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (TextLit chunks :: Chunks s a
chunks) =
    Chunks t b -> Expr t b
forall s a. Chunks s a -> Expr s a
TextLit (Chunks t b -> Expr t b) -> f (Chunks t b) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr s a -> f (Expr t b)) -> Chunks s a -> f (Chunks t b)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Chunks s a -> f (Chunks t b)
chunkExprs Expr s a -> f (Expr t b)
f Chunks s a
chunks
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (TextAppend a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
TextAppend (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions _ TextShow = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
TextShow
unsafeSubExpressions _ List = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
List
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (ListLit a :: Maybe (Expr s a)
a b :: Seq (Expr s a)
b) = Maybe (Expr t b) -> Seq (Expr t b) -> Expr t b
forall s a. Maybe (Expr s a) -> Seq (Expr s a) -> Expr s a
ListLit (Maybe (Expr t b) -> Seq (Expr t b) -> Expr t b)
-> f (Maybe (Expr t b)) -> f (Seq (Expr t b) -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr s a -> f (Expr t b))
-> Maybe (Expr s a) -> f (Maybe (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Maybe (Expr s a)
a f (Seq (Expr t b) -> Expr t b)
-> f (Seq (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr s a -> f (Expr t b)) -> Seq (Expr s a) -> f (Seq (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Seq (Expr s a)
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (ListAppend a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
ListAppend (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions _ ListBuild = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListBuild
unsafeSubExpressions _ ListFold = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListFold
unsafeSubExpressions _ ListLength = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListLength
unsafeSubExpressions _ ListHead = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListHead
unsafeSubExpressions _ ListLast = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListLast
unsafeSubExpressions _ ListIndexed = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListIndexed
unsafeSubExpressions _ ListReverse = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
ListReverse
unsafeSubExpressions _ Optional = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
Optional
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Some a :: Expr s a
a) = Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a
Some (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a
unsafeSubExpressions _ None = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
None
unsafeSubExpressions _ OptionalFold = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
OptionalFold
unsafeSubExpressions _ OptionalBuild = Expr t b -> f (Expr t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Expr t b
forall s a. Expr s a
OptionalBuild
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Record a :: Map Text (Expr s a)
a) = Map Text (Expr t b) -> Expr t b
forall s a. Map Text (Expr s a) -> Expr s a
Record (Map Text (Expr t b) -> Expr t b)
-> f (Map Text (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr s a -> f (Expr t b))
-> Map Text (Expr s a) -> f (Map Text (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Map Text (Expr s a)
a
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f ( RecordLit a :: Map Text (Expr s a)
a ) = Map Text (Expr t b) -> Expr t b
forall s a. Map Text (Expr s a) -> Expr s a
RecordLit (Map Text (Expr t b) -> Expr t b)
-> f (Map Text (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Expr s a -> f (Expr t b))
-> Map Text (Expr s a) -> f (Map Text (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Map Text (Expr s a)
a
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Union a :: Map Text (Maybe (Expr s a))
a) = Map Text (Maybe (Expr t b)) -> Expr t b
forall s a. Map Text (Maybe (Expr s a)) -> Expr s a
Union (Map Text (Maybe (Expr t b)) -> Expr t b)
-> f (Map Text (Maybe (Expr t b))) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe (Expr s a) -> f (Maybe (Expr t b)))
-> Map Text (Maybe (Expr s a)) -> f (Map Text (Maybe (Expr t b)))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr s a -> f (Expr t b))
-> Maybe (Expr s a) -> f (Maybe (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f) Map Text (Maybe (Expr s a))
a
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Combine a :: Maybe Text
a b :: Expr s a
b c :: Expr s a
c) = Maybe Text -> Expr t b -> Expr t b -> Expr t b
forall s a. Maybe Text -> Expr s a -> Expr s a -> Expr s a
Combine Maybe Text
a (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (CombineTypes a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
CombineTypes (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Prefer a :: PreferAnnotation s a
a b :: Expr s a
b c :: Expr s a
c) = PreferAnnotation t b -> Expr t b -> Expr t b -> Expr t b
forall s a.
PreferAnnotation s a -> Expr s a -> Expr s a -> Expr s a
Prefer (PreferAnnotation t b -> Expr t b -> Expr t b -> Expr t b)
-> f (PreferAnnotation t b) -> f (Expr t b -> Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (PreferAnnotation t b)
a' f (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
  where
    a' :: f (PreferAnnotation t b)
a' = case PreferAnnotation s a
a of
        PreferFromSource     -> PreferAnnotation t b -> f (PreferAnnotation t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PreferAnnotation t b
forall s a. PreferAnnotation s a
PreferFromSource
        PreferFromWith d :: Expr s a
d     -> Expr t b -> PreferAnnotation t b
forall s a. Expr s a -> PreferAnnotation s a
PreferFromWith (Expr t b -> PreferAnnotation t b)
-> f (Expr t b) -> f (PreferAnnotation t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
d
        PreferFromCompletion -> PreferAnnotation t b -> f (PreferAnnotation t b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PreferAnnotation t b
forall s a. PreferAnnotation s a
PreferFromCompletion
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (RecordCompletion a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
RecordCompletion (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Merge a :: Expr s a
a b :: Expr s a
b t :: Maybe (Expr s a)
t) = Expr t b -> Expr t b -> Maybe (Expr t b) -> Expr t b
forall s a. Expr s a -> Expr s a -> Maybe (Expr s a) -> Expr s a
Merge (Expr t b -> Expr t b -> Maybe (Expr t b) -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Maybe (Expr t b) -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Maybe (Expr t b) -> Expr t b)
-> f (Expr t b) -> f (Maybe (Expr t b) -> Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b f (Maybe (Expr t b) -> Expr t b)
-> f (Maybe (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr s a -> f (Expr t b))
-> Maybe (Expr s a) -> f (Maybe (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Maybe (Expr s a)
t
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (ToMap a :: Expr s a
a t :: Maybe (Expr s a)
t) = Expr t b -> Maybe (Expr t b) -> Expr t b
forall s a. Expr s a -> Maybe (Expr s a) -> Expr s a
ToMap (Expr t b -> Maybe (Expr t b) -> Expr t b)
-> f (Expr t b) -> f (Maybe (Expr t b) -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Maybe (Expr t b) -> Expr t b)
-> f (Maybe (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr s a -> f (Expr t b))
-> Maybe (Expr s a) -> f (Maybe (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Maybe (Expr s a)
t
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Field a :: Expr s a
a b :: Text
b) = Expr t b -> Text -> Expr t b
forall s a. Expr s a -> Text -> Expr s a
Field (Expr t b -> Text -> Expr t b)
-> f (Expr t b) -> f (Text -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Text -> Expr t b) -> f Text -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> f Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Project a :: Expr s a
a b :: Either (Set Text) (Expr s a)
b) = Expr t b -> Either (Set Text) (Expr t b) -> Expr t b
forall s a. Expr s a -> Either (Set Text) (Expr s a) -> Expr s a
Project (Expr t b -> Either (Set Text) (Expr t b) -> Expr t b)
-> f (Expr t b) -> f (Either (Set Text) (Expr t b) -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Either (Set Text) (Expr t b) -> Expr t b)
-> f (Either (Set Text) (Expr t b)) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Expr s a -> f (Expr t b))
-> Either (Set Text) (Expr s a) -> f (Either (Set Text) (Expr t b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f Either (Set Text) (Expr s a)
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Assert a :: Expr s a
a) = Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a
Assert (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (Equivalent a :: Expr s a
a b :: Expr s a
b) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
Equivalent (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
b
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (With a :: Expr s a
a b :: NonEmpty Text
b c :: Expr s a
c) = Expr t b -> NonEmpty Text -> Expr t b -> Expr t b
forall s a. Expr s a -> NonEmpty Text -> Expr s a -> Expr s a
With (Expr t b -> NonEmpty Text -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (NonEmpty Text -> Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
a f (NonEmpty Text -> Expr t b -> Expr t b)
-> f (NonEmpty Text) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> NonEmpty Text -> f (NonEmpty Text)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NonEmpty Text
b f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
c
unsafeSubExpressions f :: Expr s a -> f (Expr t b)
f (ImportAlt l :: Expr s a
l r :: Expr s a
r) = Expr t b -> Expr t b -> Expr t b
forall s a. Expr s a -> Expr s a -> Expr s a
ImportAlt (Expr t b -> Expr t b -> Expr t b)
-> f (Expr t b) -> f (Expr t b -> Expr t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr s a -> f (Expr t b)
f Expr s a
l f (Expr t b -> Expr t b) -> f (Expr t b) -> f (Expr t b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr t b)
f Expr s a
r
unsafeSubExpressions _ (Let {}) = Text -> f (Expr t b)
forall a. Text -> a
unhandledConstructor "Let"
unsafeSubExpressions _ (Note {}) = Text -> f (Expr t b)
forall a. Text -> a
unhandledConstructor "Note"
unsafeSubExpressions _ (Embed {}) = Text -> f (Expr t b)
forall a. Text -> a
unhandledConstructor "Embed"
{-# INLINABLE unsafeSubExpressions #-}

unhandledConstructor :: Text -> a
unhandledConstructor :: Text -> a
unhandledConstructor constructor :: Text
constructor =
    Text -> forall b. b
internalError
        (   "Dhall.Syntax.unsafeSubExpressions: Unhandled "
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>  Text
constructor
        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>  " construtor"
        )

{-| Traverse over the immediate 'Expr' children in a 'Binding'.
-}
bindingExprs
  :: (Applicative f)
  => (Expr s a -> f (Expr s b))
  -> Binding s a -> f (Binding s b)
bindingExprs :: (Expr s a -> f (Expr s b)) -> Binding s a -> f (Binding s b)
bindingExprs f :: Expr s a -> f (Expr s b)
f (Binding s0 :: Maybe s
s0 n :: Text
n s1 :: Maybe s
s1 t :: Maybe (Maybe s, Expr s a)
t s2 :: Maybe s
s2 v :: Expr s a
v) =
  Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s b)
-> Maybe s
-> Expr s b
-> Binding s b
forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding
    (Maybe s
 -> Text
 -> Maybe s
 -> Maybe (Maybe s, Expr s b)
 -> Maybe s
 -> Expr s b
 -> Binding s b)
-> f (Maybe s)
-> f (Text
      -> Maybe s
      -> Maybe (Maybe s, Expr s b)
      -> Maybe s
      -> Expr s b
      -> Binding s b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe s -> f (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe s
s0
    f (Text
   -> Maybe s
   -> Maybe (Maybe s, Expr s b)
   -> Maybe s
   -> Expr s b
   -> Binding s b)
-> f Text
-> f (Maybe s
      -> Maybe (Maybe s, Expr s b) -> Maybe s -> Expr s b -> Binding s b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Text -> f Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
n
    f (Maybe s
   -> Maybe (Maybe s, Expr s b) -> Maybe s -> Expr s b -> Binding s b)
-> f (Maybe s)
-> f (Maybe (Maybe s, Expr s b)
      -> Maybe s -> Expr s b -> Binding s b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe s -> f (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe s
s1
    f (Maybe (Maybe s, Expr s b) -> Maybe s -> Expr s b -> Binding s b)
-> f (Maybe (Maybe s, Expr s b))
-> f (Maybe s -> Expr s b -> Binding s b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((Maybe s, Expr s a) -> f (Maybe s, Expr s b))
-> Maybe (Maybe s, Expr s a) -> f (Maybe (Maybe s, Expr s b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr s a -> f (Expr s b))
-> (Maybe s, Expr s a) -> f (Maybe s, Expr s b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr s b)
f) Maybe (Maybe s, Expr s a)
t
    f (Maybe s -> Expr s b -> Binding s b)
-> f (Maybe s) -> f (Expr s b -> Binding s b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe s -> f (Maybe s)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe s
s2
    f (Expr s b -> Binding s b) -> f (Expr s b) -> f (Binding s b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Expr s a -> f (Expr s b)
f Expr s a
v
{-# INLINABLE bindingExprs #-}

-- | A traversal over the immediate sub-expressions in 'Chunks'.
chunkExprs
  :: Applicative f
  => (Expr s a -> f (Expr t b))
  -> Chunks s a -> f (Chunks t b)
chunkExprs :: (Expr s a -> f (Expr t b)) -> Chunks s a -> f (Chunks t b)
chunkExprs f :: Expr s a -> f (Expr t b)
f (Chunks chunks :: [(Text, Expr s a)]
chunks final :: Text
final) =
  ([(Text, Expr t b)] -> Text -> Chunks t b)
-> Text -> [(Text, Expr t b)] -> Chunks t b
forall a b c. (a -> b -> c) -> b -> a -> c
flip [(Text, Expr t b)] -> Text -> Chunks t b
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks Text
final ([(Text, Expr t b)] -> Chunks t b)
-> f [(Text, Expr t b)] -> f (Chunks t b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Text, Expr s a) -> f (Text, Expr t b))
-> [(Text, Expr s a)] -> f [(Text, Expr t b)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Expr s a -> f (Expr t b))
-> (Text, Expr s a) -> f (Text, Expr t b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Expr s a -> f (Expr t b)
f) [(Text, Expr s a)]
chunks
{-# INLINABLE chunkExprs #-}

{-| 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" ] }@
-}
newtype Directory = Directory { Directory -> [Text]
components :: [Text] }
    deriving (Directory -> Directory -> Bool
(Directory -> Directory -> Bool)
-> (Directory -> Directory -> Bool) -> Eq Directory
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Directory -> Directory -> Bool
$c/= :: Directory -> Directory -> Bool
== :: Directory -> Directory -> Bool
$c== :: Directory -> Directory -> Bool
Eq, (forall x. Directory -> Rep Directory x)
-> (forall x. Rep Directory x -> Directory) -> Generic Directory
forall x. Rep Directory x -> Directory
forall x. Directory -> Rep Directory x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Directory x -> Directory
$cfrom :: forall x. Directory -> Rep Directory x
Generic, Eq Directory
Eq Directory =>
(Directory -> Directory -> Ordering)
-> (Directory -> Directory -> Bool)
-> (Directory -> Directory -> Bool)
-> (Directory -> Directory -> Bool)
-> (Directory -> Directory -> Bool)
-> (Directory -> Directory -> Directory)
-> (Directory -> Directory -> Directory)
-> Ord Directory
Directory -> Directory -> Bool
Directory -> Directory -> Ordering
Directory -> Directory -> Directory
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Directory -> Directory -> Directory
$cmin :: Directory -> Directory -> Directory
max :: Directory -> Directory -> Directory
$cmax :: Directory -> Directory -> Directory
>= :: Directory -> Directory -> Bool
$c>= :: Directory -> Directory -> Bool
> :: Directory -> Directory -> Bool
$c> :: Directory -> Directory -> Bool
<= :: Directory -> Directory -> Bool
$c<= :: Directory -> Directory -> Bool
< :: Directory -> Directory -> Bool
$c< :: Directory -> Directory -> Bool
compare :: Directory -> Directory -> Ordering
$ccompare :: Directory -> Directory -> Ordering
$cp1Ord :: Eq Directory
Ord, Int -> Directory -> ShowS
[Directory] -> ShowS
Directory -> String
(Int -> Directory -> ShowS)
-> (Directory -> String)
-> ([Directory] -> ShowS)
-> Show Directory
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Directory] -> ShowS
$cshowList :: [Directory] -> ShowS
show :: Directory -> String
$cshow :: Directory -> String
showsPrec :: Int -> Directory -> ShowS
$cshowsPrec :: Int -> Directory -> ShowS
Show, Directory -> ()
(Directory -> ()) -> NFData Directory
forall a. (a -> ()) -> NFData a
rnf :: Directory -> ()
$crnf :: Directory -> ()
NFData)

instance Semigroup Directory where
    Directory components₀ :: [Text]
components₀ <> :: Directory -> Directory -> Directory
<> Directory components₁ :: [Text]
components₁ =
        [Text] -> Directory
Directory ([Text]
components₁ [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text]
components₀)

instance Pretty Directory where
    pretty :: Directory -> Doc ann
pretty (Directory {..}) = (Text -> Doc ann) -> [Text] -> Doc ann
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Text -> Doc ann
forall ann. Text -> Doc ann
prettyPathComponent ([Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
components)

prettyPathComponent :: Text -> Doc ann
prettyPathComponent :: Text -> Doc ann
prettyPathComponent text :: Text
text
    | (Char -> Bool) -> Text -> Bool
Data.Text.all Char -> Bool
pathCharacter Text
text =
        "/" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Text
text
    | Bool
otherwise =
        "/\"" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Text
text Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> "\""

{-| A `File` is a `directory` followed by one additional path component
    representing the `file` name
-}
data File = File
    { File -> Directory
directory :: Directory
    , File -> Text
file      :: Text
    } deriving (File -> File -> Bool
(File -> File -> Bool) -> (File -> File -> Bool) -> Eq File
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: File -> File -> Bool
$c/= :: File -> File -> Bool
== :: File -> File -> Bool
$c== :: File -> File -> Bool
Eq, (forall x. File -> Rep File x)
-> (forall x. Rep File x -> File) -> Generic File
forall x. Rep File x -> File
forall x. File -> Rep File x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep File x -> File
$cfrom :: forall x. File -> Rep File x
Generic, Eq File
Eq File =>
(File -> File -> Ordering)
-> (File -> File -> Bool)
-> (File -> File -> Bool)
-> (File -> File -> Bool)
-> (File -> File -> Bool)
-> (File -> File -> File)
-> (File -> File -> File)
-> Ord File
File -> File -> Bool
File -> File -> Ordering
File -> File -> File
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: File -> File -> File
$cmin :: File -> File -> File
max :: File -> File -> File
$cmax :: File -> File -> File
>= :: File -> File -> Bool
$c>= :: File -> File -> Bool
> :: File -> File -> Bool
$c> :: File -> File -> Bool
<= :: File -> File -> Bool
$c<= :: File -> File -> Bool
< :: File -> File -> Bool
$c< :: File -> File -> Bool
compare :: File -> File -> Ordering
$ccompare :: File -> File -> Ordering
$cp1Ord :: Eq File
Ord, Int -> File -> ShowS
[File] -> ShowS
File -> String
(Int -> File -> ShowS)
-> (File -> String) -> ([File] -> ShowS) -> Show File
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [File] -> ShowS
$cshowList :: [File] -> ShowS
show :: File -> String
$cshow :: File -> String
showsPrec :: Int -> File -> ShowS
$cshowsPrec :: Int -> File -> ShowS
Show, File -> ()
(File -> ()) -> NFData File
forall a. (a -> ()) -> NFData a
rnf :: File -> ()
$crnf :: File -> ()
NFData)

instance Pretty File where
    pretty :: File -> Doc ann
pretty (File {..}) =
            Directory -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Directory
directory
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  Text -> Doc ann
forall ann. Text -> Doc ann
prettyPathComponent Text
file

instance Semigroup File where
    File directory₀ :: Directory
directory₀ _ <> :: File -> File -> File
<> File directory₁ :: Directory
directory₁ file :: Text
file =
        Directory -> Text -> File
File (Directory
directory₀ Directory -> Directory -> Directory
forall a. Semigroup a => a -> a -> a
<> Directory
directory₁) Text
file

-- | The beginning of a file path which anchors subsequent path components
data FilePrefix
    = Absolute
    -- ^ Absolute path
    | Here
    -- ^ Path relative to @.@
    | Parent
    -- ^ Path relative to @..@
    | Home
    -- ^ Path relative to @~@
    deriving (FilePrefix -> FilePrefix -> Bool
(FilePrefix -> FilePrefix -> Bool)
-> (FilePrefix -> FilePrefix -> Bool) -> Eq FilePrefix
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilePrefix -> FilePrefix -> Bool
$c/= :: FilePrefix -> FilePrefix -> Bool
== :: FilePrefix -> FilePrefix -> Bool
$c== :: FilePrefix -> FilePrefix -> Bool
Eq, (forall x. FilePrefix -> Rep FilePrefix x)
-> (forall x. Rep FilePrefix x -> FilePrefix) -> Generic FilePrefix
forall x. Rep FilePrefix x -> FilePrefix
forall x. FilePrefix -> Rep FilePrefix x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FilePrefix x -> FilePrefix
$cfrom :: forall x. FilePrefix -> Rep FilePrefix x
Generic, Eq FilePrefix
Eq FilePrefix =>
(FilePrefix -> FilePrefix -> Ordering)
-> (FilePrefix -> FilePrefix -> Bool)
-> (FilePrefix -> FilePrefix -> Bool)
-> (FilePrefix -> FilePrefix -> Bool)
-> (FilePrefix -> FilePrefix -> Bool)
-> (FilePrefix -> FilePrefix -> FilePrefix)
-> (FilePrefix -> FilePrefix -> FilePrefix)
-> Ord FilePrefix
FilePrefix -> FilePrefix -> Bool
FilePrefix -> FilePrefix -> Ordering
FilePrefix -> FilePrefix -> FilePrefix
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FilePrefix -> FilePrefix -> FilePrefix
$cmin :: FilePrefix -> FilePrefix -> FilePrefix
max :: FilePrefix -> FilePrefix -> FilePrefix
$cmax :: FilePrefix -> FilePrefix -> FilePrefix
>= :: FilePrefix -> FilePrefix -> Bool
$c>= :: FilePrefix -> FilePrefix -> Bool
> :: FilePrefix -> FilePrefix -> Bool
$c> :: FilePrefix -> FilePrefix -> Bool
<= :: FilePrefix -> FilePrefix -> Bool
$c<= :: FilePrefix -> FilePrefix -> Bool
< :: FilePrefix -> FilePrefix -> Bool
$c< :: FilePrefix -> FilePrefix -> Bool
compare :: FilePrefix -> FilePrefix -> Ordering
$ccompare :: FilePrefix -> FilePrefix -> Ordering
$cp1Ord :: Eq FilePrefix
Ord, Int -> FilePrefix -> ShowS
[FilePrefix] -> ShowS
FilePrefix -> String
(Int -> FilePrefix -> ShowS)
-> (FilePrefix -> String)
-> ([FilePrefix] -> ShowS)
-> Show FilePrefix
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilePrefix] -> ShowS
$cshowList :: [FilePrefix] -> ShowS
show :: FilePrefix -> String
$cshow :: FilePrefix -> String
showsPrec :: Int -> FilePrefix -> ShowS
$cshowsPrec :: Int -> FilePrefix -> ShowS
Show, FilePrefix -> ()
(FilePrefix -> ()) -> NFData FilePrefix
forall a. (a -> ()) -> NFData a
rnf :: FilePrefix -> ()
$crnf :: FilePrefix -> ()
NFData)

instance Pretty FilePrefix where
    pretty :: FilePrefix -> Doc ann
pretty Absolute = ""
    pretty Here     = "."
    pretty Parent   = ".."
    pretty Home     = "~"

-- | The URI scheme
data Scheme = HTTP | HTTPS deriving (Scheme -> Scheme -> Bool
(Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool) -> Eq Scheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Scheme -> Scheme -> Bool
$c/= :: Scheme -> Scheme -> Bool
== :: Scheme -> Scheme -> Bool
$c== :: Scheme -> Scheme -> Bool
Eq, (forall x. Scheme -> Rep Scheme x)
-> (forall x. Rep Scheme x -> Scheme) -> Generic Scheme
forall x. Rep Scheme x -> Scheme
forall x. Scheme -> Rep Scheme x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Scheme x -> Scheme
$cfrom :: forall x. Scheme -> Rep Scheme x
Generic, Eq Scheme
Eq Scheme =>
(Scheme -> Scheme -> Ordering)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Scheme)
-> (Scheme -> Scheme -> Scheme)
-> Ord Scheme
Scheme -> Scheme -> Bool
Scheme -> Scheme -> Ordering
Scheme -> Scheme -> Scheme
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Scheme -> Scheme -> Scheme
$cmin :: Scheme -> Scheme -> Scheme
max :: Scheme -> Scheme -> Scheme
$cmax :: Scheme -> Scheme -> Scheme
>= :: Scheme -> Scheme -> Bool
$c>= :: Scheme -> Scheme -> Bool
> :: Scheme -> Scheme -> Bool
$c> :: Scheme -> Scheme -> Bool
<= :: Scheme -> Scheme -> Bool
$c<= :: Scheme -> Scheme -> Bool
< :: Scheme -> Scheme -> Bool
$c< :: Scheme -> Scheme -> Bool
compare :: Scheme -> Scheme -> Ordering
$ccompare :: Scheme -> Scheme -> Ordering
$cp1Ord :: Eq Scheme
Ord, Int -> Scheme -> ShowS
[Scheme] -> ShowS
Scheme -> String
(Int -> Scheme -> ShowS)
-> (Scheme -> String) -> ([Scheme] -> ShowS) -> Show Scheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Scheme] -> ShowS
$cshowList :: [Scheme] -> ShowS
show :: Scheme -> String
$cshow :: Scheme -> String
showsPrec :: Int -> Scheme -> ShowS
$cshowsPrec :: Int -> Scheme -> ShowS
Show, Scheme -> ()
(Scheme -> ()) -> NFData Scheme
forall a. (a -> ()) -> NFData a
rnf :: Scheme -> ()
$crnf :: Scheme -> ()
NFData)

-- | This type stores all of the components of a remote import
data URL = URL
    { URL -> Scheme
scheme    :: Scheme
    , URL -> Text
authority :: Text
    , URL -> File
path      :: File
    , URL -> Maybe Text
query     :: Maybe Text
    , URL -> Maybe (Expr Src Import)
headers   :: Maybe (Expr Src Import)
    } deriving (URL -> URL -> Bool
(URL -> URL -> Bool) -> (URL -> URL -> Bool) -> Eq URL
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: URL -> URL -> Bool
$c/= :: URL -> URL -> Bool
== :: URL -> URL -> Bool
$c== :: URL -> URL -> Bool
Eq, (forall x. URL -> Rep URL x)
-> (forall x. Rep URL x -> URL) -> Generic URL
forall x. Rep URL x -> URL
forall x. URL -> Rep URL x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep URL x -> URL
$cfrom :: forall x. URL -> Rep URL x
Generic, Eq URL
Eq URL =>
(URL -> URL -> Ordering)
-> (URL -> URL -> Bool)
-> (URL -> URL -> Bool)
-> (URL -> URL -> Bool)
-> (URL -> URL -> Bool)
-> (URL -> URL -> URL)
-> (URL -> URL -> URL)
-> Ord URL
URL -> URL -> Bool
URL -> URL -> Ordering
URL -> URL -> URL
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: URL -> URL -> URL
$cmin :: URL -> URL -> URL
max :: URL -> URL -> URL
$cmax :: URL -> URL -> URL
>= :: URL -> URL -> Bool
$c>= :: URL -> URL -> Bool
> :: URL -> URL -> Bool
$c> :: URL -> URL -> Bool
<= :: URL -> URL -> Bool
$c<= :: URL -> URL -> Bool
< :: URL -> URL -> Bool
$c< :: URL -> URL -> Bool
compare :: URL -> URL -> Ordering
$ccompare :: URL -> URL -> Ordering
$cp1Ord :: Eq URL
Ord, Int -> URL -> ShowS
[URL] -> ShowS
URL -> String
(Int -> URL -> ShowS)
-> (URL -> String) -> ([URL] -> ShowS) -> Show URL
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [URL] -> ShowS
$cshowList :: [URL] -> ShowS
show :: URL -> String
$cshow :: URL -> String
showsPrec :: Int -> URL -> ShowS
$cshowsPrec :: Int -> URL -> ShowS
Show, URL -> ()
(URL -> ()) -> NFData URL
forall a. (a -> ()) -> NFData a
rnf :: URL -> ()
$crnf :: URL -> ()
NFData)

instance Pretty URL where
    pretty :: URL -> Doc ann
pretty (URL {..}) =
            Doc ann
schemeDoc
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  "://"
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Text
authority
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  Doc ann
forall ann. Doc ann
pathDoc
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  Doc ann
forall ann. Doc ann
queryDoc
        Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  (Expr Src Import -> Doc ann) -> Maybe (Expr Src Import) -> Doc ann
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Expr Src Import -> Doc ann
forall a ann. Pretty a => a -> Doc ann
prettyHeaders Maybe (Expr Src Import)
headers
      where
        prettyHeaders :: a -> Doc ann
prettyHeaders h :: a
h = " using " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> a -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty a
h

        File {..} = File
path

        Directory {..} = Directory
directory

        pathDoc :: Doc ann
pathDoc =
                (Text -> Doc ann) -> [Text] -> Doc ann
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Text -> Doc ann
forall ann. Text -> Doc ann
prettyURIComponent ([Text] -> [Text]
forall a. [a] -> [a]
reverse [Text]
components)
            Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<>  Text -> Doc ann
forall ann. Text -> Doc ann
prettyURIComponent Text
file

        schemeDoc :: Doc ann
schemeDoc = case Scheme
scheme of
            HTTP  -> "http"
            HTTPS -> "https"

        queryDoc :: Doc ann
queryDoc = case Maybe Text
query of
            Nothing -> ""
            Just q :: Text
q  -> "?" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Text
q

prettyURIComponent :: Text -> Doc ann
prettyURIComponent :: Text -> Doc ann
prettyURIComponent text :: Text
text =
        String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty (String -> Doc ann) -> String -> Doc ann
forall a b. (a -> b) -> a -> b
$ ShowS
URI.normalizeCase ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ ShowS
URI.normalizeEscape ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ "/" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
Data.Text.unpack Text
text

-- | The type of import (i.e. local vs. remote vs. environment)
data ImportType
    = Local FilePrefix File
    -- ^ Local path
    | Remote URL
    -- ^ URL of remote resource and optional headers stored in an import
    | Env  Text
    -- ^ Environment variable
    | Missing
    deriving (ImportType -> ImportType -> Bool
(ImportType -> ImportType -> Bool)
-> (ImportType -> ImportType -> Bool) -> Eq ImportType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportType -> ImportType -> Bool
$c/= :: ImportType -> ImportType -> Bool
== :: ImportType -> ImportType -> Bool
$c== :: ImportType -> ImportType -> Bool
Eq, (forall x. ImportType -> Rep ImportType x)
-> (forall x. Rep ImportType x -> ImportType) -> Generic ImportType
forall x. Rep ImportType x -> ImportType
forall x. ImportType -> Rep ImportType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImportType x -> ImportType
$cfrom :: forall x. ImportType -> Rep ImportType x
Generic, Eq ImportType
Eq ImportType =>
(ImportType -> ImportType -> Ordering)
-> (ImportType -> ImportType -> Bool)
-> (ImportType -> ImportType -> Bool)
-> (ImportType -> ImportType -> Bool)
-> (ImportType -> ImportType -> Bool)
-> (ImportType -> ImportType -> ImportType)
-> (ImportType -> ImportType -> ImportType)
-> Ord ImportType
ImportType -> ImportType -> Bool
ImportType -> ImportType -> Ordering
ImportType -> ImportType -> ImportType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ImportType -> ImportType -> ImportType
$cmin :: ImportType -> ImportType -> ImportType
max :: ImportType -> ImportType -> ImportType
$cmax :: ImportType -> ImportType -> ImportType
>= :: ImportType -> ImportType -> Bool
$c>= :: ImportType -> ImportType -> Bool
> :: ImportType -> ImportType -> Bool
$c> :: ImportType -> ImportType -> Bool
<= :: ImportType -> ImportType -> Bool
$c<= :: ImportType -> ImportType -> Bool
< :: ImportType -> ImportType -> Bool
$c< :: ImportType -> ImportType -> Bool
compare :: ImportType -> ImportType -> Ordering
$ccompare :: ImportType -> ImportType -> Ordering
$cp1Ord :: Eq ImportType
Ord, Int -> ImportType -> ShowS
[ImportType] -> ShowS
ImportType -> String
(Int -> ImportType -> ShowS)
-> (ImportType -> String)
-> ([ImportType] -> ShowS)
-> Show ImportType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportType] -> ShowS
$cshowList :: [ImportType] -> ShowS
show :: ImportType -> String
$cshow :: ImportType -> String
showsPrec :: Int -> ImportType -> ShowS
$cshowsPrec :: Int -> ImportType -> ShowS
Show, ImportType -> ()
(ImportType -> ()) -> NFData ImportType
forall a. (a -> ()) -> NFData a
rnf :: ImportType -> ()
$crnf :: ImportType -> ()
NFData)

parent :: File
parent :: File
parent = File :: Directory -> Text -> File
File { directory :: Directory
directory = Directory :: [Text] -> Directory
Directory { components :: [Text]
components = [ ".." ] }, file :: Text
file = "" }

instance Semigroup ImportType where
    Local prefix :: FilePrefix
prefix file₀ :: File
file₀ <> :: ImportType -> ImportType -> ImportType
<> Local Here file₁ :: File
file₁ = FilePrefix -> File -> ImportType
Local FilePrefix
prefix (File
file₀ File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
file₁)

    Remote (URL { path :: URL -> File
path = File
path₀, ..}) <> Local Here path₁ :: File
path₁ =
        URL -> ImportType
Remote (URL :: Scheme
-> Text -> File -> Maybe Text -> Maybe (Expr Src Import) -> URL
URL { path :: File
path = File
path₀ File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
path₁, ..})

    Local prefix :: FilePrefix
prefix file₀ :: File
file₀ <> Local Parent file₁ :: File
file₁ =
        FilePrefix -> File -> ImportType
Local FilePrefix
prefix (File
file₀ File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
parent File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
file₁)

    Remote (URL { path :: URL -> File
path = File
path₀, .. }) <> Local Parent path₁ :: File
path₁ =
        URL -> ImportType
Remote (URL :: Scheme
-> Text -> File -> Maybe Text -> Maybe (Expr Src Import) -> URL
URL { path :: File
path = File
path₀ File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
parent File -> File -> File
forall a. Semigroup a => a -> a -> a
<> File
path₁, .. })

    import₀ :: ImportType
import₀ <> Remote (URL { headers :: URL -> Maybe (Expr Src Import)
headers = Maybe (Expr Src Import)
headers₀, .. }) =
        URL -> ImportType
Remote (URL :: Scheme
-> Text -> File -> Maybe Text -> Maybe (Expr Src Import) -> URL
URL { headers :: Maybe (Expr Src Import)
headers = Maybe (Expr Src Import)
headers₁, .. })
      where
        importHashed₀ :: Import
importHashed₀ = ImportHashed -> ImportMode -> Import
Import (Maybe SHA256Digest -> ImportType -> ImportHashed
ImportHashed Maybe SHA256Digest
forall a. Maybe a
Nothing ImportType
import₀) ImportMode
Code

        headers₁ :: Maybe (Expr Src Import)
headers₁ = (Expr Src Import -> Expr Src Import)
-> Maybe (Expr Src Import) -> Maybe (Expr Src Import)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Import -> Import) -> Expr Src Import -> Expr Src Import
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Import
importHashed₀ Import -> Import -> Import
forall a. Semigroup a => a -> a -> a
<>)) Maybe (Expr Src Import)
headers₀

    _ <> import₁ :: ImportType
import₁ =
        ImportType
import₁

instance Pretty ImportType where
    pretty :: ImportType -> Doc ann
pretty (Local prefix :: FilePrefix
prefix file :: File
file) =
        FilePrefix -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty FilePrefix
prefix Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> File -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty File
file

    pretty (Remote url :: URL
url) = URL -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty URL
url

    pretty (Env env :: Text
env) = "env:" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall ann. Text -> Doc ann
prettyEnvironmentVariable Text
env

    pretty Missing = "missing"

-- | How to interpret the import's contents (i.e. as Dhall code or raw text)
data ImportMode = Code | RawText | Location
  deriving (ImportMode -> ImportMode -> Bool
(ImportMode -> ImportMode -> Bool)
-> (ImportMode -> ImportMode -> Bool) -> Eq ImportMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportMode -> ImportMode -> Bool
$c/= :: ImportMode -> ImportMode -> Bool
== :: ImportMode -> ImportMode -> Bool
$c== :: ImportMode -> ImportMode -> Bool
Eq, (forall x. ImportMode -> Rep ImportMode x)
-> (forall x. Rep ImportMode x -> ImportMode) -> Generic ImportMode
forall x. Rep ImportMode x -> ImportMode
forall x. ImportMode -> Rep ImportMode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImportMode x -> ImportMode
$cfrom :: forall x. ImportMode -> Rep ImportMode x
Generic, Eq ImportMode
Eq ImportMode =>
(ImportMode -> ImportMode -> Ordering)
-> (ImportMode -> ImportMode -> Bool)
-> (ImportMode -> ImportMode -> Bool)
-> (ImportMode -> ImportMode -> Bool)
-> (ImportMode -> ImportMode -> Bool)
-> (ImportMode -> ImportMode -> ImportMode)
-> (ImportMode -> ImportMode -> ImportMode)
-> Ord ImportMode
ImportMode -> ImportMode -> Bool
ImportMode -> ImportMode -> Ordering
ImportMode -> ImportMode -> ImportMode
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ImportMode -> ImportMode -> ImportMode
$cmin :: ImportMode -> ImportMode -> ImportMode
max :: ImportMode -> ImportMode -> ImportMode
$cmax :: ImportMode -> ImportMode -> ImportMode
>= :: ImportMode -> ImportMode -> Bool
$c>= :: ImportMode -> ImportMode -> Bool
> :: ImportMode -> ImportMode -> Bool
$c> :: ImportMode -> ImportMode -> Bool
<= :: ImportMode -> ImportMode -> Bool
$c<= :: ImportMode -> ImportMode -> Bool
< :: ImportMode -> ImportMode -> Bool
$c< :: ImportMode -> ImportMode -> Bool
compare :: ImportMode -> ImportMode -> Ordering
$ccompare :: ImportMode -> ImportMode -> Ordering
$cp1Ord :: Eq ImportMode
Ord, Int -> ImportMode -> ShowS
[ImportMode] -> ShowS
ImportMode -> String
(Int -> ImportMode -> ShowS)
-> (ImportMode -> String)
-> ([ImportMode] -> ShowS)
-> Show ImportMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportMode] -> ShowS
$cshowList :: [ImportMode] -> ShowS
show :: ImportMode -> String
$cshow :: ImportMode -> String
showsPrec :: Int -> ImportMode -> ShowS
$cshowsPrec :: Int -> ImportMode -> ShowS
Show, ImportMode -> ()
(ImportMode -> ()) -> NFData ImportMode
forall a. (a -> ()) -> NFData a
rnf :: ImportMode -> ()
$crnf :: ImportMode -> ()
NFData)

-- | A `ImportType` extended with an optional hash for semantic integrity checks
data ImportHashed = ImportHashed
    { ImportHashed -> Maybe SHA256Digest
hash       :: Maybe Dhall.Crypto.SHA256Digest
    , ImportHashed -> ImportType
importType :: ImportType
    } deriving (ImportHashed -> ImportHashed -> Bool
(ImportHashed -> ImportHashed -> Bool)
-> (ImportHashed -> ImportHashed -> Bool) -> Eq ImportHashed
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportHashed -> ImportHashed -> Bool
$c/= :: ImportHashed -> ImportHashed -> Bool
== :: ImportHashed -> ImportHashed -> Bool
$c== :: ImportHashed -> ImportHashed -> Bool
Eq, (forall x. ImportHashed -> Rep ImportHashed x)
-> (forall x. Rep ImportHashed x -> ImportHashed)
-> Generic ImportHashed
forall x. Rep ImportHashed x -> ImportHashed
forall x. ImportHashed -> Rep ImportHashed x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImportHashed x -> ImportHashed
$cfrom :: forall x. ImportHashed -> Rep ImportHashed x
Generic, Eq ImportHashed
Eq ImportHashed =>
(ImportHashed -> ImportHashed -> Ordering)
-> (ImportHashed -> ImportHashed -> Bool)
-> (ImportHashed -> ImportHashed -> Bool)
-> (ImportHashed -> ImportHashed -> Bool)
-> (ImportHashed -> ImportHashed -> Bool)
-> (ImportHashed -> ImportHashed -> ImportHashed)
-> (ImportHashed -> ImportHashed -> ImportHashed)
-> Ord ImportHashed
ImportHashed -> ImportHashed -> Bool
ImportHashed -> ImportHashed -> Ordering
ImportHashed -> ImportHashed -> ImportHashed
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ImportHashed -> ImportHashed -> ImportHashed
$cmin :: ImportHashed -> ImportHashed -> ImportHashed
max :: ImportHashed -> ImportHashed -> ImportHashed
$cmax :: ImportHashed -> ImportHashed -> ImportHashed
>= :: ImportHashed -> ImportHashed -> Bool
$c>= :: ImportHashed -> ImportHashed -> Bool
> :: ImportHashed -> ImportHashed -> Bool
$c> :: ImportHashed -> ImportHashed -> Bool
<= :: ImportHashed -> ImportHashed -> Bool
$c<= :: ImportHashed -> ImportHashed -> Bool
< :: ImportHashed -> ImportHashed -> Bool
$c< :: ImportHashed -> ImportHashed -> Bool
compare :: ImportHashed -> ImportHashed -> Ordering
$ccompare :: ImportHashed -> ImportHashed -> Ordering
$cp1Ord :: Eq ImportHashed
Ord, Int -> ImportHashed -> ShowS
[ImportHashed] -> ShowS
ImportHashed -> String
(Int -> ImportHashed -> ShowS)
-> (ImportHashed -> String)
-> ([ImportHashed] -> ShowS)
-> Show ImportHashed
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportHashed] -> ShowS
$cshowList :: [ImportHashed] -> ShowS
show :: ImportHashed -> String
$cshow :: ImportHashed -> String
showsPrec :: Int -> ImportHashed -> ShowS
$cshowsPrec :: Int -> ImportHashed -> ShowS
Show, ImportHashed -> ()
(ImportHashed -> ()) -> NFData ImportHashed
forall a. (a -> ()) -> NFData a
rnf :: ImportHashed -> ()
$crnf :: ImportHashed -> ()
NFData)

instance Semigroup ImportHashed where
    ImportHashed _ importType₀ :: ImportType
importType₀ <> :: ImportHashed -> ImportHashed -> ImportHashed
<> ImportHashed hash :: Maybe SHA256Digest
hash importType₁ :: ImportType
importType₁ =
        Maybe SHA256Digest -> ImportType -> ImportHashed
ImportHashed Maybe SHA256Digest
hash (ImportType
importType₀ ImportType -> ImportType -> ImportType
forall a. Semigroup a => a -> a -> a
<> ImportType
importType₁)

instance Pretty ImportHashed where
    pretty :: ImportHashed -> Doc ann
pretty (ImportHashed  Nothing p :: ImportType
p) =
      ImportType -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty ImportType
p
    pretty (ImportHashed (Just h :: SHA256Digest
h) p :: ImportType
p) =
      ImportType -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty ImportType
p Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> " sha256:" Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty (SHA256Digest -> String
forall a. Show a => a -> String
show SHA256Digest
h)

-- | Reference to an external resource
data Import = Import
    { Import -> ImportHashed
importHashed :: ImportHashed
    , Import -> ImportMode
importMode   :: ImportMode
    } deriving (Import -> Import -> Bool
(Import -> Import -> Bool)
-> (Import -> Import -> Bool) -> Eq Import
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Import -> Import -> Bool
$c/= :: Import -> Import -> Bool
== :: Import -> Import -> Bool
$c== :: Import -> Import -> Bool
Eq, (forall x. Import -> Rep Import x)
-> (forall x. Rep Import x -> Import) -> Generic Import
forall x. Rep Import x -> Import
forall x. Import -> Rep Import x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Import x -> Import
$cfrom :: forall x. Import -> Rep Import x
Generic, Eq Import
Eq Import =>
(Import -> Import -> Ordering)
-> (Import -> Import -> Bool)
-> (Import -> Import -> Bool)
-> (Import -> Import -> Bool)
-> (Import -> Import -> Bool)
-> (Import -> Import -> Import)
-> (Import -> Import -> Import)
-> Ord Import
Import -> Import -> Bool
Import -> Import -> Ordering
Import -> Import -> Import
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Import -> Import -> Import
$cmin :: Import -> Import -> Import
max :: Import -> Import -> Import
$cmax :: Import -> Import -> Import
>= :: Import -> Import -> Bool
$c>= :: Import -> Import -> Bool
> :: Import -> Import -> Bool
$c> :: Import -> Import -> Bool
<= :: Import -> Import -> Bool
$c<= :: Import -> Import -> Bool
< :: Import -> Import -> Bool
$c< :: Import -> Import -> Bool
compare :: Import -> Import -> Ordering
$ccompare :: Import -> Import -> Ordering
$cp1Ord :: Eq Import
Ord, Int -> Import -> ShowS
[Import] -> ShowS
Import -> String
(Int -> Import -> ShowS)
-> (Import -> String) -> ([Import] -> ShowS) -> Show Import
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Import] -> ShowS
$cshowList :: [Import] -> ShowS
show :: Import -> String
$cshow :: Import -> String
showsPrec :: Int -> Import -> ShowS
$cshowsPrec :: Int -> Import -> ShowS
Show, Import -> ()
(Import -> ()) -> NFData Import
forall a. (a -> ()) -> NFData a
rnf :: Import -> ()
$crnf :: Import -> ()
NFData)

instance Semigroup Import where
    Import importHashed₀ :: ImportHashed
importHashed₀ _ <> :: Import -> Import -> Import
<> Import importHashed₁ :: ImportHashed
importHashed₁ code :: ImportMode
code =
        ImportHashed -> ImportMode -> Import
Import (ImportHashed
importHashed₀ ImportHashed -> ImportHashed -> ImportHashed
forall a. Semigroup a => a -> a -> a
<> ImportHashed
importHashed₁) ImportMode
code

instance Pretty Import where
    pretty :: Import -> Doc ann
pretty (Import {..}) = ImportHashed -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty ImportHashed
importHashed Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall a ann. Pretty a => a -> Doc ann
Pretty.pretty Text
suffix
      where
        suffix :: Text
        suffix :: Text
suffix = case ImportMode
importMode of
            RawText  -> " as Text"
            Location -> " as Location"
            Code     -> ""

{-| Returns `True` if the given `Char` is valid within an unquoted path
    component

    This is exported for reuse within the @"Dhall.Parser.Token"@ module
-}
pathCharacter :: Char -> Bool
pathCharacter :: Char -> Bool
pathCharacter c :: Char
c =
         '\x21' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c
    Bool -> Bool -> Bool
||  ('\x24' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x27')
    Bool -> Bool -> Bool
||  ('\x2A' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x2B')
    Bool -> Bool -> Bool
||  ('\x2D' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x2E')
    Bool -> Bool -> Bool
||  ('\x30' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x3B')
    Bool -> Bool -> Bool
||  Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\x3D'
    Bool -> Bool -> Bool
||  ('\x40' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x5A')
    Bool -> Bool -> Bool
||  ('\x5E' Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= Char
c Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
<= '\x7A')
    Bool -> Bool -> Bool
||  Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\x7C'
    Bool -> Bool -> Bool
||  Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\x7E'

-- | Remove all `Note` constructors from an `Expr` (i.e. de-`Note`)
denote :: Expr s a -> Expr t a
denote :: Expr s a -> Expr t a
denote (Note _ b :: Expr s a
b     ) = Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
b
denote (Let a :: Binding s a
a b :: Expr s a
b      ) = Binding t a -> Expr t a -> Expr t a
forall s a. Binding s a -> Expr s a -> Expr s a
Let (Binding s a -> Binding t a
forall s a s. Binding s a -> Binding s a
adapt0 Binding s a
a) (Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
b)
  where
    adapt0 :: Binding s a -> Binding s a
adapt0 (Binding _ c :: Text
c _ d :: Maybe (Maybe s, Expr s a)
d _ e :: Expr s a
e) =
        Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
forall s a.
Maybe s
-> Text
-> Maybe s
-> Maybe (Maybe s, Expr s a)
-> Maybe s
-> Expr s a
-> Binding s a
Binding Maybe s
forall a. Maybe a
Nothing Text
c Maybe s
forall a. Maybe a
Nothing (((Maybe s, Expr s a) -> (Maybe s, Expr s a))
-> Maybe (Maybe s, Expr s a) -> Maybe (Maybe s, Expr s a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe s, Expr s a) -> (Maybe s, Expr s a)
forall a s a a t. (a, Expr s a) -> (Maybe a, Expr t a)
adapt1 Maybe (Maybe s, Expr s a)
d) Maybe s
forall a. Maybe a
Nothing (Expr s a -> Expr s a
forall s a t. Expr s a -> Expr t a
denote Expr s a
e)

    adapt1 :: (a, Expr s a) -> (Maybe a, Expr t a)
adapt1 (_, f :: Expr s a
f) = (Maybe a
forall a. Maybe a
Nothing, Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
f)
denote (Embed a :: a
a      ) = a -> Expr t a
forall s a. a -> Expr s a
Embed a
a
denote (Combine _ b :: Expr s a
b c :: Expr s a
c) = Maybe Text -> Expr t a -> Expr t a -> Expr t a
forall s a. Maybe Text -> Expr s a -> Expr s a -> Expr s a
Combine Maybe Text
forall a. Maybe a
Nothing (Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
b) (Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
c)
denote  expression :: Expr s a
expression     = ASetter (Expr s a) (Expr t a) (Expr s a) (Expr t a)
-> (Expr s a -> Expr t a) -> Expr s a -> Expr t a
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
Lens.over ASetter (Expr s a) (Expr t a) (Expr s a) (Expr t a)
forall (f :: * -> *) s a t b.
Applicative f =>
(Expr s a -> f (Expr t b)) -> Expr s a -> f (Expr t b)
unsafeSubExpressions Expr s a -> Expr t a
forall s a t. Expr s a -> Expr t a
denote Expr s a
expression

-- | The \"opposite\" of `denote`, like @first absurd@ but faster
renote :: Expr Void a -> Expr s a
renote :: Expr Void a -> Expr s a
renote = Expr Void a -> Expr s a
forall a b. a -> b
unsafeCoerce
{-# INLINE renote #-}

{-| Remove any outermost `Note` constructors

    This is typically used when you want to get the outermost non-`Note`
    constructor without removing internal `Note` constructors
-}
shallowDenote :: Expr s a -> Expr s a
shallowDenote :: Expr s a -> Expr s a
shallowDenote (Note _ e :: Expr s a
e) = Expr s a -> Expr s a
forall s a. Expr s a -> Expr s a
shallowDenote Expr s a
e
shallowDenote         e :: Expr s a
e  = Expr s a
e

-- | The set of reserved identifiers for the Dhall language
reservedIdentifiers :: HashSet Text
reservedIdentifiers :: HashSet Text
reservedIdentifiers =
    [Text] -> HashSet Text
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Data.HashSet.fromList
        [ -- Keywords according to the `keyword` rule in the grammar
          "if"
        , "then"
        , "else"
        , "let"
        , "in"
        , "using"
        , "missing"
        , "as"
        , "Infinity"
        , "NaN"
        , "merge"
        , "Some"
        , "toMap"
        , "assert"
        , "forall"
        , "with"

          -- Builtins according to the `builtin` rule in the grammar
        , "Natural/fold"
        , "Natural/build"
        , "Natural/isZero"
        , "Natural/even"
        , "Natural/odd"
        , "Natural/toInteger"
        , "Natural/show"
        , "Natural/subtract"
        , "Integer"
        , "Integer/clamp"
        , "Integer/negate"
        , "Integer/show"
        , "Integer/toDouble"
        , "Integer/show"
        , "Natural/subtract"
        , "Double/show"
        , "List/build"
        , "List/fold"
        , "List/length"
        , "List/head"
        , "List/last"
        , "List/indexed"
        , "List/reverse"
        , "Optional/fold"
        , "Optional/build"
        , "Text/show"
        , "Bool"
        , "True"
        , "False"
        , "Optional"
        , "None"
        , "Natural"
        , "Integer"
        , "Double"
        , "Text"
        , "List"
        , "Type"
        , "Kind"
        , "Sort"
        ]

-- | Same as @Data.Text.splitOn@, except always returning a `NonEmpty` result
splitOn :: Text -> Text -> NonEmpty Text
splitOn :: Text -> Text -> NonEmpty Text
splitOn needle :: Text
needle haystack :: Text
haystack =
    case Text -> Text -> [Text]
Data.Text.splitOn Text
needle Text
haystack of
        []     -> "" Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| []
        t :: Text
t : ts :: [Text]
ts -> Text
t  Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| [Text]
ts

-- | Split `Chunks` by lines
linesLiteral :: Chunks s a -> NonEmpty (Chunks s a)
linesLiteral :: Chunks s a -> NonEmpty (Chunks s a)
linesLiteral (Chunks [] suffix :: Text
suffix) =
    (Text -> Chunks s a) -> NonEmpty Text -> NonEmpty (Chunks s a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks []) (Text -> Text -> NonEmpty Text
splitOn "\n" Text
suffix)
linesLiteral (Chunks ((prefix :: Text
prefix, interpolation :: Expr s a
interpolation) : pairs₀ :: [(Text, Expr s a)]
pairs₀) suffix₀ :: Text
suffix₀) =
    (Chunks s a -> NonEmpty (Chunks s a) -> NonEmpty (Chunks s a))
-> NonEmpty (Chunks s a) -> [Chunks s a] -> NonEmpty (Chunks s a)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
        Chunks s a -> NonEmpty (Chunks s a) -> NonEmpty (Chunks s a)
forall a. a -> NonEmpty a -> NonEmpty a
NonEmpty.cons
        ([(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks ((Text
lastLine, Expr s a
interpolation) (Text, Expr s a) -> [(Text, Expr s a)] -> [(Text, Expr s a)]
forall a. a -> [a] -> [a]
: [(Text, Expr s a)]
pairs₁) Text
suffix₁ Chunks s a -> [Chunks s a] -> NonEmpty (Chunks s a)
forall a. a -> [a] -> NonEmpty a
:| [Chunks s a]
chunks)
        ((Text -> Chunks s a) -> [Text] -> [Chunks s a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks []) [Text]
initLines)
  where
    splitLines :: NonEmpty Text
splitLines = Text -> Text -> NonEmpty Text
splitOn "\n" Text
prefix

    initLines :: [Text]
initLines = NonEmpty Text -> [Text]
forall a. NonEmpty a -> [a]
NonEmpty.init NonEmpty Text
splitLines
    lastLine :: Text
lastLine  = NonEmpty Text -> Text
forall a. NonEmpty a -> a
NonEmpty.last NonEmpty Text
splitLines

    Chunks pairs₁ :: [(Text, Expr s a)]
pairs₁ suffix₁ :: Text
suffix₁ :| chunks :: [Chunks s a]
chunks = Chunks s a -> NonEmpty (Chunks s a)
forall s a. Chunks s a -> NonEmpty (Chunks s a)
linesLiteral ([(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks [(Text, Expr s a)]
pairs₀ Text
suffix₀)

-- | Flatten several `Chunks` back into a single `Chunks` by inserting newlines
unlinesLiteral :: NonEmpty (Chunks s a) -> Chunks s a
unlinesLiteral :: NonEmpty (Chunks s a) -> Chunks s a
unlinesLiteral chunks :: NonEmpty (Chunks s a)
chunks =
    NonEmpty (Chunks s a) -> Chunks s a
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
Data.Foldable.fold (Chunks s a -> NonEmpty (Chunks s a) -> NonEmpty (Chunks s a)
forall a. a -> NonEmpty a -> NonEmpty a
NonEmpty.intersperse "\n" NonEmpty (Chunks s a)
chunks)

-- | Returns `True` if the `Chunks` represents a blank line
emptyLine :: Chunks s a -> Bool
emptyLine :: Chunks s a -> Bool
emptyLine (Chunks [] ""  ) = Bool
True
emptyLine (Chunks [] "\r") = Bool
True  -- So that `\r\n` is treated as a blank line
emptyLine  _               = Bool
False

-- | Return the leading whitespace for a `Chunks` literal
leadingSpaces :: Chunks s a -> Text
leadingSpaces :: Chunks s a -> Text
leadingSpaces chunks :: Chunks s a
chunks = (Char -> Bool) -> Text -> Text
Data.Text.takeWhile Char -> Bool
isSpace Text
firstText
  where
    isSpace :: Char -> Bool
isSpace c :: Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== ' ' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '\t'

    firstText :: Text
firstText =
        case Chunks s a
chunks of
            Chunks                []  suffix :: Text
suffix -> Text
suffix
            Chunks ((prefix :: Text
prefix, _) : _ ) _      -> Text
prefix

{-| Compute the longest shared whitespace prefix for the purposes of stripping
    leading indentation
-}
longestSharedWhitespacePrefix :: NonEmpty (Chunks s a) -> Text
longestSharedWhitespacePrefix :: NonEmpty (Chunks s a) -> Text
longestSharedWhitespacePrefix literals :: NonEmpty (Chunks s a)
literals =
    case (Chunks s a -> Text) -> [Chunks s a] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Chunks s a -> Text
forall s a. Chunks s a -> Text
leadingSpaces [Chunks s a]
filteredLines of
        l :: Text
l : ls :: [Text]
ls -> (Text -> Text -> Text) -> Text -> [Text] -> Text
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Data.Foldable.foldl' Text -> Text -> Text
sharedPrefix Text
l [Text]
ls
        []     -> ""
  where
    sharedPrefix :: Text -> Text -> Text
sharedPrefix ab :: Text
ab ac :: Text
ac =
        case Text -> Text -> Maybe (Text, Text, Text)
Data.Text.commonPrefixes Text
ab Text
ac of
            Just (a :: Text
a, _b :: Text
_b, _c :: Text
_c) -> Text
a
            Nothing          -> ""

    -- The standard specifies to filter out blank lines for all lines *except*
    -- for the last line
    filteredLines :: [Chunks s a]
filteredLines = [Chunks s a]
newInit [Chunks s a] -> [Chunks s a] -> [Chunks s a]
forall a. Semigroup a => a -> a -> a
<> Chunks s a -> [Chunks s a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure Chunks s a
oldLast
      where
        oldInit :: [Chunks s a]
oldInit = NonEmpty (Chunks s a) -> [Chunks s a]
forall a. NonEmpty a -> [a]
NonEmpty.init NonEmpty (Chunks s a)
literals

        oldLast :: Chunks s a
oldLast = NonEmpty (Chunks s a) -> Chunks s a
forall a. NonEmpty a -> a
NonEmpty.last NonEmpty (Chunks s a)
literals

        newInit :: [Chunks s a]
newInit = (Chunks s a -> Bool) -> [Chunks s a] -> [Chunks s a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Chunks s a -> Bool) -> Chunks s a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Chunks s a -> Bool
forall s a. Chunks s a -> Bool
emptyLine) [Chunks s a]
oldInit

-- | Drop the first @n@ characters for a `Chunks` literal
dropLiteral :: Int -> Chunks s a -> Chunks s a
dropLiteral :: Int -> Chunks s a -> Chunks s a
dropLiteral n :: Int
n (Chunks [] suffix :: Text
suffix) =
    [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks [] (Int -> Text -> Text
Data.Text.drop Int
n Text
suffix)
dropLiteral n :: Int
n (Chunks ((prefix :: Text
prefix, interpolation :: Expr s a
interpolation) : rest :: [(Text, Expr s a)]
rest) suffix :: Text
suffix) =
    [(Text, Expr s a)] -> Text -> Chunks s a
forall s a. [(Text, Expr s a)] -> Text -> Chunks s a
Chunks ((Int -> Text -> Text
Data.Text.drop Int
n Text
prefix, Expr s a
interpolation) (Text, Expr s a) -> [(Text, Expr s a)] -> [(Text, Expr s a)]
forall a. a -> [a] -> [a]
: [(Text, Expr s a)]
rest) Text
suffix

{-| Convert a single-quoted `Chunks` literal to the equivalent double-quoted
    `Chunks` literal
-}
toDoubleQuoted :: Chunks Src a -> Chunks Src a
toDoubleQuoted :: Chunks Src a -> Chunks Src a
toDoubleQuoted literal :: Chunks Src a
literal =
    NonEmpty (Chunks Src a) -> Chunks Src a
forall s a. NonEmpty (Chunks s a) -> Chunks s a
unlinesLiteral ((Chunks Src a -> Chunks Src a)
-> NonEmpty (Chunks Src a) -> NonEmpty (Chunks Src a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Chunks Src a -> Chunks Src a
forall s a. Int -> Chunks s a -> Chunks s a
dropLiteral Int
indent) NonEmpty (Chunks Src a)
literals)
  where
    literals :: NonEmpty (Chunks Src a)
literals = Chunks Src a -> NonEmpty (Chunks Src a)
forall s a. Chunks s a -> NonEmpty (Chunks s a)
linesLiteral Chunks Src a
literal

    longestSharedPrefix :: Text
longestSharedPrefix = NonEmpty (Chunks Src a) -> Text
forall s a. NonEmpty (Chunks s a) -> Text
longestSharedWhitespacePrefix NonEmpty (Chunks Src a)
literals

    indent :: Int
indent = Text -> Int
Data.Text.length Text
longestSharedPrefix

-- | Desugar all @with@ expressions
desugarWith :: Expr s a -> Expr s a
desugarWith :: Expr s a -> Expr s a
desugarWith = ASetter (Expr s a) (Expr s a) (Expr s a) (Expr s a)
-> (Expr s a -> Maybe (Expr s a)) -> Expr s a -> Expr s a
forall a b. ASetter a b a b -> (b -> Maybe a) -> a -> b
Optics.rewriteOf ASetter (Expr s a) (Expr s a) (Expr s a) (Expr s a)
forall (f :: * -> *) s a.
Applicative f =>
(Expr s a -> f (Expr s a)) -> Expr s a -> f (Expr s a)
subExpressions Expr s a -> Maybe (Expr s a)
forall s a. Expr s a -> Maybe (Expr s a)
rewrite
  where
    rewrite :: Expr s a -> Maybe (Expr s a)
rewrite e :: Expr s a
e@(With record :: Expr s a
record (key :: Text
key :| []) value :: Expr s a
value) =
        Expr s a -> Maybe (Expr s a)
forall a. a -> Maybe a
Just (PreferAnnotation s a -> Expr s a -> Expr s a -> Expr s a
forall s a.
PreferAnnotation s a -> Expr s a -> Expr s a -> Expr s a
Prefer (Expr s a -> PreferAnnotation s a
forall s a. Expr s a -> PreferAnnotation s a
PreferFromWith Expr s a
e) Expr s a
record (Map Text (Expr s a) -> Expr s a
forall s a. Map Text (Expr s a) -> Expr s a
RecordLit [ (Text
key, Expr s a
value) ]))
    rewrite e :: Expr s a
e@(With record :: Expr s a
record (key0 :: Text
key0 :| key1 :: Text
key1 : keys :: [Text]
keys) value :: Expr s a
value) =
        Expr s a -> Maybe (Expr s a)
forall a. a -> Maybe a
Just
            (PreferAnnotation s a -> Expr s a -> Expr s a -> Expr s a
forall s a.
PreferAnnotation s a -> Expr s a -> Expr s a -> Expr s a
Prefer (Expr s a -> PreferAnnotation s a
forall s a. Expr s a -> PreferAnnotation s a
PreferFromWith Expr s a
e) Expr s a
record
                (Map Text (Expr s a) -> Expr s a
forall s a. Map Text (Expr s a) -> Expr s a
RecordLit
                    [ (Text
key0, Expr s a -> NonEmpty Text -> Expr s a -> Expr s a
forall s a. Expr s a -> NonEmpty Text -> Expr s a -> Expr s a
With (Expr s a -> Text -> Expr s a
forall s a. Expr s a -> Text -> Expr s a
Field Expr s a
record Text
key0) (Text
key1 Text -> [Text] -> NonEmpty Text
forall a. a -> [a] -> NonEmpty a
:| [Text]
keys) Expr s a
value) ]
                )
            )
    rewrite _ = Maybe (Expr s a)
forall a. Maybe a
Nothing

_ERROR :: String
_ERROR :: String
_ERROR = "\ESC[1;31mError\ESC[0m"

{-| Utility function used to throw internal errors that should never happen
    (in theory) but that are not enforced by the type system
-}
internalError :: Data.Text.Text -> forall b . b
internalError :: Text -> forall b. b
internalError text :: Text
text = String -> b
forall a. HasCallStack => String -> a
error ([String] -> String
unlines
    [ String
_ERROR String -> ShowS
forall a. Semigroup a => a -> a -> a
<> ": Compiler bug                                                        "
    , "                                                                                "
    , "Explanation: This error message means that there is a bug in the Dhall compiler."
    , "You didn't do anything wrong, but if you would like to see this problem fixed   "
    , "then you should report the bug at:                                              "
    , "                                                                                "
    , "https://github.com/dhall-lang/dhall-haskell/issues                              "
    , "                                                                                "
    , "Please include the following text in your bug report:                           "
    , "                                                                                "
    , "```                                                                             "
    , Text -> String
Data.Text.unpack Text
text String -> ShowS
forall a. Semigroup a => a -> a -> a
<> "                                                       "
    , "```                                                                             "
    ] )