module Nix.Expr.Shorthands where
import Nix.Prelude
import Data.Fix
import Nix.Atoms
import Nix.Expr.Types
mkConst :: NAtom -> NExpr
mkConst :: NAtom -> NExpr
mkConst = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NAtom -> NExprF NExpr) -> NAtom -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NExprF NExpr
forall r. NAtom -> NExprF r
NConstant
mkNull :: NExpr
mkNull :: NExpr
mkNull = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix NExprF NExpr
forall a. NExprF a
mkNullF
mkBool :: Bool -> NExpr
mkBool :: Bool -> NExpr
mkBool = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Bool -> NExprF NExpr) -> Bool -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NExprF NExpr
forall a. Bool -> NExprF a
mkBoolF
mkInt :: Integer -> NExpr
mkInt :: Integer -> NExpr
mkInt = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (Integer -> NExprF NExpr) -> Integer -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NExprF NExpr
forall a. Integer -> NExprF a
mkIntF
mkFloat :: Float -> NExpr
mkFloat :: Float -> NExpr
mkFloat = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (Float -> NExprF NExpr) -> Float -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> NExprF NExpr
forall a. Float -> NExprF a
mkFloatF
mkStr :: Text -> NExpr
mkStr :: Text -> NExpr
mkStr = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Text -> NExprF NExpr) -> Text -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NString NExpr -> NExprF NExpr
forall r. NString r -> NExprF r
NStr (NString NExpr -> NExprF NExpr)
-> (Text -> NString NExpr) -> Text -> NExprF NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Antiquoted Text NExpr] -> NString NExpr
forall r. [Antiquoted Text r] -> NString r
DoubleQuoted ([Antiquoted Text NExpr] -> NString NExpr)
-> (Text -> [Antiquoted Text NExpr]) -> Text -> NString NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Antiquoted Text NExpr]
-> (Text -> [Antiquoted Text NExpr])
-> Text
-> [Antiquoted Text NExpr]
forall a. a -> (Text -> a) -> Text -> a
whenText
[Antiquoted Text NExpr]
forall a. Monoid a => a
mempty
(Antiquoted Text NExpr -> [Antiquoted Text NExpr]
forall x. One x => OneItem x -> x
one (Antiquoted Text NExpr -> [Antiquoted Text NExpr])
-> (Text -> Antiquoted Text NExpr)
-> Text
-> [Antiquoted Text NExpr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Antiquoted Text NExpr
forall v r. v -> Antiquoted v r
Plain)
mkIndentedStr :: Int -> Text -> NExpr
mkIndentedStr :: Int -> Text -> NExpr
mkIndentedStr Int
w = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Text -> NExprF NExpr) -> Text -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NString NExpr -> NExprF NExpr
forall r. NString r -> NExprF r
NStr (NString NExpr -> NExprF NExpr)
-> (Text -> NString NExpr) -> Text -> NExprF NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Antiquoted Text NExpr] -> NString NExpr
forall r. Int -> [Antiquoted Text r] -> NString r
Indented Int
w ([Antiquoted Text NExpr] -> NString NExpr)
-> (Text -> [Antiquoted Text NExpr]) -> Text -> NString NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Antiquoted Text NExpr]
-> (Text -> [Antiquoted Text NExpr])
-> Text
-> [Antiquoted Text NExpr]
forall a. a -> (Text -> a) -> Text -> a
whenText
[Antiquoted Text NExpr]
forall a. Monoid a => a
mempty
(Antiquoted Text NExpr -> [Antiquoted Text NExpr]
forall x. One x => OneItem x -> x
one (Antiquoted Text NExpr -> [Antiquoted Text NExpr])
-> (Text -> Antiquoted Text NExpr)
-> Text
-> [Antiquoted Text NExpr]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Antiquoted Text NExpr
forall v r. v -> Antiquoted v r
Plain)
mkPath :: Bool -> FilePath -> NExpr
mkPath :: Bool -> FilePath -> NExpr
mkPath Bool
b = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (FilePath -> NExprF NExpr) -> FilePath -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> FilePath -> NExprF NExpr
forall a. Bool -> FilePath -> NExprF a
mkPathF Bool
b
mkEnvPath :: FilePath -> NExpr
mkEnvPath :: FilePath -> NExpr
mkEnvPath = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (FilePath -> NExprF NExpr) -> FilePath -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> NExprF NExpr
forall a. FilePath -> NExprF a
mkEnvPathF
mkRelPath :: FilePath -> NExpr
mkRelPath :: FilePath -> NExpr
mkRelPath = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (FilePath -> NExprF NExpr) -> FilePath -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> NExprF NExpr
forall a. FilePath -> NExprF a
mkRelPathF
mkSym :: Text -> NExpr
mkSym :: Text -> NExpr
mkSym = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Text -> NExprF NExpr) -> Text -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NExprF NExpr
forall a. Text -> NExprF a
mkSymF
mkSynHole :: Text -> NExpr
mkSynHole :: Text -> NExpr
mkSynHole = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Text -> NExprF NExpr) -> Text -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NExprF NExpr
forall a. Text -> NExprF a
mkSynHoleF
mkSelector :: Text -> NAttrPath NExpr
mkSelector :: Text -> NAttrPath NExpr
mkSelector = NKeyName NExpr -> NAttrPath NExpr
forall x. One x => OneItem x -> x
one (NKeyName NExpr -> NAttrPath NExpr)
-> (Text -> NKeyName NExpr) -> Text -> NAttrPath NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VarName -> NKeyName NExpr
forall r. VarName -> NKeyName r
StaticKey (VarName -> NKeyName NExpr)
-> (Text -> VarName) -> Text -> NKeyName NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> VarName
coerce
mkOp :: NUnaryOp -> NExpr -> NExpr
mkOp :: NUnaryOp -> NExpr -> NExpr
mkOp NUnaryOp
op = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NUnaryOp -> NExpr -> NExprF NExpr
forall r. NUnaryOp -> r -> NExprF r
NUnary NUnaryOp
op
mkNot :: NExpr -> NExpr
mkNot :: NExpr -> NExpr
mkNot = NUnaryOp -> NExpr -> NExpr
mkOp NUnaryOp
NNot
mkNeg :: NExpr -> NExpr
mkNeg :: NExpr -> NExpr
mkNeg = NUnaryOp -> NExpr -> NExpr
mkOp NUnaryOp
NNeg
mkOp2 :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
op NExpr
a = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NBinaryOp -> NExpr -> NExpr -> NExprF NExpr
forall r. NBinaryOp -> r -> r -> NExprF r
NBinary NBinaryOp
op NExpr
a
mkParamSet :: [(Text, Maybe NExpr)] -> Params NExpr
mkParamSet :: [(Text, Maybe NExpr)] -> Params NExpr
mkParamSet [(Text, Maybe NExpr)]
pset = Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet Maybe Text
forall a. Maybe a
Nothing [(Text, Maybe NExpr)]
pset Bool
False
mkVariadicParamSet :: [(Text, Maybe NExpr)] -> Params NExpr
mkVariadicParamSet :: [(Text, Maybe NExpr)] -> Params NExpr
mkVariadicParamSet [(Text, Maybe NExpr)]
pset = Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet Maybe Text
forall a. Maybe a
Nothing [(Text, Maybe NExpr)]
pset Bool
True
mkNamedParamSet :: Text -> [(Text, Maybe NExpr)] -> Params NExpr
mkNamedParamSet :: Text -> [(Text, Maybe NExpr)] -> Params NExpr
mkNamedParamSet Text
name [(Text, Maybe NExpr)]
pset = Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet (Text -> Maybe Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
name) [(Text, Maybe NExpr)]
pset Bool
False
mkNamedVariadicParamSet :: Text -> [(Text, Maybe NExpr)] -> Params NExpr
mkNamedVariadicParamSet :: Text -> [(Text, Maybe NExpr)] -> Params NExpr
mkNamedVariadicParamSet Text
name [(Text, Maybe NExpr)]
params = Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet (Text -> Maybe Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
name) [(Text, Maybe NExpr)]
params Bool
True
mkGeneralParamSet :: Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet :: Maybe Text -> [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkGeneralParamSet Maybe Text
mname [(Text, Maybe NExpr)]
params Bool
variadic = Maybe VarName -> Variadic -> ParamSet NExpr -> Params NExpr
forall r. Maybe VarName -> Variadic -> ParamSet r -> Params r
ParamSet (Maybe Text -> Maybe VarName
coerce Maybe Text
mname) (Variadic
Variadic Variadic -> Bool -> Variadic
forall a. Monoid a => a -> Bool -> a
`whenTrue` Bool
variadic) ([(Text, Maybe NExpr)] -> ParamSet NExpr
coerce [(Text, Maybe NExpr)]
params)
mkRecSet :: [Binding NExpr] -> NExpr
mkRecSet :: [Binding NExpr] -> NExpr
mkRecSet = Recursivity -> [Binding NExpr] -> NExpr
mkSet Recursivity
Recursive
mkNonRecSet :: [Binding NExpr] -> NExpr
mkNonRecSet :: [Binding NExpr] -> NExpr
mkNonRecSet = Recursivity -> [Binding NExpr] -> NExpr
mkSet Recursivity
forall a. Monoid a => a
mempty
mkSet :: Recursivity -> [Binding NExpr] -> NExpr
mkSet :: Recursivity -> [Binding NExpr] -> NExpr
mkSet Recursivity
r = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> ([Binding NExpr] -> NExprF NExpr) -> [Binding NExpr] -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Recursivity -> [Binding NExpr] -> NExprF NExpr
forall r. Recursivity -> [Binding r] -> NExprF r
NSet Recursivity
r
emptySet :: NExpr
emptySet :: NExpr
emptySet = [Binding NExpr] -> NExpr
mkNonRecSet [Binding NExpr]
forall a. Monoid a => a
mempty
mkList :: [NExpr] -> NExpr
mkList :: [NExpr] -> NExpr
mkList = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> ([NExpr] -> NExprF NExpr) -> [NExpr] -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NExpr] -> NExprF NExpr
forall r. [r] -> NExprF r
NList
emptyList :: NExpr
emptyList :: NExpr
emptyList = [NExpr] -> NExpr
mkList [NExpr]
forall a. Monoid a => a
mempty
mkLets :: [Binding NExpr] -> NExpr -> NExpr
mkLets :: [Binding NExpr] -> NExpr -> NExpr
mkLets [Binding NExpr]
bindings = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Binding NExpr] -> NExpr -> NExprF NExpr
forall r. [Binding r] -> r -> NExprF r
NLet [Binding NExpr]
bindings
mkWith :: NExpr -> NExpr -> NExpr
mkWith :: NExpr -> NExpr -> NExpr
mkWith NExpr
e = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NExpr -> NExpr -> NExprF NExpr
forall r. r -> r -> NExprF r
NWith NExpr
e
mkAssert :: NExpr -> NExpr -> NExpr
mkAssert :: NExpr -> NExpr -> NExpr
mkAssert NExpr
e = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NExpr -> NExpr -> NExprF NExpr
forall r. r -> r -> NExprF r
NAssert NExpr
e
mkIf :: NExpr -> NExpr -> NExpr -> NExpr
mkIf :: NExpr -> NExpr -> NExpr -> NExpr
mkIf NExpr
e1 NExpr
e2 = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NExpr -> NExpr -> NExpr -> NExprF NExpr
forall r. r -> r -> r -> NExprF r
NIf NExpr
e1 NExpr
e2
mkFunction :: Params NExpr -> NExpr -> NExpr
mkFunction :: Params NExpr -> NExpr -> NExpr
mkFunction Params NExpr
params = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr)
-> (NExpr -> NExprF NExpr) -> NExpr -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Params NExpr -> NExpr -> NExprF NExpr
forall r. Params r -> r -> NExprF r
NAbs Params NExpr
params
getRefOrDefault :: Maybe NExpr -> NExpr -> Text -> NExpr
getRefOrDefault :: Maybe NExpr -> NExpr -> Text -> NExpr
getRefOrDefault Maybe NExpr
alt NExpr
obj = NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> (Text -> NExprF NExpr) -> Text -> NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe NExpr -> NExpr -> NAttrPath NExpr -> NExprF NExpr
forall r. Maybe r -> r -> NAttrPath r -> NExprF r
NSelect Maybe NExpr
alt NExpr
obj (NAttrPath NExpr -> NExprF NExpr)
-> (Text -> NAttrPath NExpr) -> Text -> NExprF NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NAttrPath NExpr
mkSelector
mkNullF :: NExprF a
mkNullF :: NExprF a
mkNullF = NAtom -> NExprF a
forall r. NAtom -> NExprF r
NConstant NAtom
NNull
mkBoolF :: Bool -> NExprF a
mkBoolF :: Bool -> NExprF a
mkBoolF = NAtom -> NExprF a
forall r. NAtom -> NExprF r
NConstant (NAtom -> NExprF a) -> (Bool -> NAtom) -> Bool -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NAtom
NBool
mkIntF :: Integer -> NExprF a
mkIntF :: Integer -> NExprF a
mkIntF = NAtom -> NExprF a
forall r. NAtom -> NExprF r
NConstant (NAtom -> NExprF a) -> (Integer -> NAtom) -> Integer -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NAtom
NInt
mkFloatF :: Float -> NExprF a
mkFloatF :: Float -> NExprF a
mkFloatF = NAtom -> NExprF a
forall r. NAtom -> NExprF r
NConstant (NAtom -> NExprF a) -> (Float -> NAtom) -> Float -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> NAtom
NFloat
mkPathF :: Bool -> FilePath -> NExprF a
mkPathF :: Bool -> FilePath -> NExprF a
mkPathF Bool
False = Path -> NExprF a
forall r. Path -> NExprF r
NLiteralPath (Path -> NExprF a) -> (FilePath -> Path) -> FilePath -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Path
coerce
mkPathF Bool
True = Path -> NExprF a
forall r. Path -> NExprF r
NEnvPath (Path -> NExprF a) -> (FilePath -> Path) -> FilePath -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Path
coerce
mkEnvPathF :: FilePath -> NExprF a
mkEnvPathF :: FilePath -> NExprF a
mkEnvPathF = Bool -> FilePath -> NExprF a
forall a. Bool -> FilePath -> NExprF a
mkPathF Bool
True
mkRelPathF :: FilePath -> NExprF a
mkRelPathF :: FilePath -> NExprF a
mkRelPathF = Bool -> FilePath -> NExprF a
forall a. Bool -> FilePath -> NExprF a
mkPathF Bool
False
mkSymF :: Text -> NExprF a
mkSymF :: Text -> NExprF a
mkSymF = VarName -> NExprF a
forall r. VarName -> NExprF r
NSym (VarName -> NExprF a) -> (Text -> VarName) -> Text -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> VarName
coerce
mkSynHoleF :: Text -> NExprF a
mkSynHoleF :: Text -> NExprF a
mkSynHoleF = VarName -> NExprF a
forall r. VarName -> NExprF r
NSynHole (VarName -> NExprF a) -> (Text -> VarName) -> Text -> NExprF a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> VarName
coerce
inheritFrom :: e -> [VarName] -> Binding e
inheritFrom :: e -> [VarName] -> Binding e
inheritFrom e
expr [VarName]
ks = Maybe e -> [VarName] -> SourcePos -> Binding e
forall r. Maybe r -> [VarName] -> SourcePos -> Binding r
Inherit (e -> Maybe e
forall (f :: * -> *) a. Applicative f => a -> f a
pure e
expr) [VarName]
ks SourcePos
nullPos
inherit :: [VarName] -> Binding e
inherit :: [VarName] -> Binding e
inherit [VarName]
ks = Maybe e -> [VarName] -> SourcePos -> Binding e
forall r. Maybe r -> [VarName] -> SourcePos -> Binding r
Inherit Maybe e
forall a. Maybe a
Nothing [VarName]
ks SourcePos
nullPos
($=) :: Text -> NExpr -> Binding NExpr
$= :: Text -> NExpr -> Binding NExpr
($=) = Text -> NExpr -> Binding NExpr
bindTo
infixr 2 $=
bindTo :: Text -> NExpr -> Binding NExpr
bindTo :: Text -> NExpr -> Binding NExpr
bindTo Text
name NExpr
x = NAttrPath NExpr -> NExpr -> SourcePos -> Binding NExpr
forall r. NAttrPath r -> r -> SourcePos -> Binding r
NamedVar (Text -> NAttrPath NExpr
mkSelector Text
name) NExpr
x SourcePos
nullPos
appendBindings :: [Binding NExpr] -> NExpr -> NExpr
appendBindings :: [Binding NExpr] -> NExpr -> NExpr
appendBindings [Binding NExpr]
newBindings (Fix NExprF NExpr
e) =
case NExprF NExpr
e of
NLet [Binding NExpr]
bindings NExpr
e' -> [Binding NExpr] -> NExpr -> NExpr
mkLets ([Binding NExpr]
bindings [Binding NExpr] -> [Binding NExpr] -> [Binding NExpr]
forall a. Semigroup a => a -> a -> a
<> [Binding NExpr]
newBindings) NExpr
e'
NSet Recursivity
recur [Binding NExpr]
bindings -> NExprF NExpr -> NExpr
forall (f :: * -> *). f (Fix f) -> Fix f
Fix (NExprF NExpr -> NExpr) -> NExprF NExpr -> NExpr
forall a b. (a -> b) -> a -> b
$ Recursivity -> [Binding NExpr] -> NExprF NExpr
forall r. Recursivity -> [Binding r] -> NExprF r
NSet Recursivity
recur ([Binding NExpr]
bindings [Binding NExpr] -> [Binding NExpr] -> [Binding NExpr]
forall a. Semigroup a => a -> a -> a
<> [Binding NExpr]
newBindings)
NExprF NExpr
_ -> Text -> NExpr
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Can only append bindings to a set or a let"
modifyFunctionBody :: (NExpr -> NExpr) -> NExpr -> NExpr
modifyFunctionBody :: (NExpr -> NExpr) -> NExpr -> NExpr
modifyFunctionBody NExpr -> NExpr
transform (Fix (NAbs Params NExpr
params NExpr
body)) = Params NExpr -> NExpr -> NExpr
mkFunction Params NExpr
params (NExpr -> NExpr) -> NExpr -> NExpr
forall a b. (a -> b) -> a -> b
$ NExpr -> NExpr
transform NExpr
body
modifyFunctionBody NExpr -> NExpr
_ NExpr
_ = Text -> NExpr
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Not a function"
letsE :: [(Text, NExpr)] -> NExpr -> NExpr
letsE :: [(Text, NExpr)] -> NExpr -> NExpr
letsE [(Text, NExpr)]
pairs = [Binding NExpr] -> NExpr -> NExpr
mkLets ([Binding NExpr] -> NExpr -> NExpr)
-> [Binding NExpr] -> NExpr -> NExpr
forall a b. (a -> b) -> a -> b
$ (Text -> NExpr -> Binding NExpr) -> (Text, NExpr) -> Binding NExpr
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> NExpr -> Binding NExpr
($=) ((Text, NExpr) -> Binding NExpr)
-> [(Text, NExpr)] -> [Binding NExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, NExpr)]
pairs
letE :: Text -> NExpr -> NExpr -> NExpr
letE :: Text -> NExpr -> NExpr -> NExpr
letE Text
varName NExpr
varExpr = [(Text, NExpr)] -> NExpr -> NExpr
letsE ([(Text, NExpr)] -> NExpr -> NExpr)
-> [(Text, NExpr)] -> NExpr -> NExpr
forall a b. (a -> b) -> a -> b
$ OneItem [(Text, NExpr)] -> [(Text, NExpr)]
forall x. One x => OneItem x -> x
one (Text
varName, NExpr
varExpr)
attrsE :: [(Text, NExpr)] -> NExpr
attrsE :: [(Text, NExpr)] -> NExpr
attrsE [(Text, NExpr)]
pairs = [Binding NExpr] -> NExpr
mkNonRecSet ([Binding NExpr] -> NExpr) -> [Binding NExpr] -> NExpr
forall a b. (a -> b) -> a -> b
$ (Text -> NExpr -> Binding NExpr) -> (Text, NExpr) -> Binding NExpr
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> NExpr -> Binding NExpr
($=) ((Text, NExpr) -> Binding NExpr)
-> [(Text, NExpr)] -> [Binding NExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, NExpr)]
pairs
recAttrsE :: [(Text, NExpr)] -> NExpr
recAttrsE :: [(Text, NExpr)] -> NExpr
recAttrsE [(Text, NExpr)]
pairs = [Binding NExpr] -> NExpr
mkRecSet ([Binding NExpr] -> NExpr) -> [Binding NExpr] -> NExpr
forall a b. (a -> b) -> a -> b
$ (Text -> NExpr -> Binding NExpr) -> (Text, NExpr) -> Binding NExpr
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Text -> NExpr -> Binding NExpr
($=) ((Text, NExpr) -> Binding NExpr)
-> [(Text, NExpr)] -> [Binding NExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Text, NExpr)]
pairs
(@@), ($==), ($!=), ($<), ($<=), ($>), ($>=), ($&&), ($||), ($->), ($//), ($+), ($-), ($*), ($/), ($++)
:: NExpr -> NExpr -> NExpr
(@.) :: NExpr -> Text -> NExpr
@. :: NExpr -> Text -> NExpr
(@.) = Maybe NExpr -> NExpr -> Text -> NExpr
getRefOrDefault Maybe NExpr
forall a. Maybe a
Nothing
infix 9 @.
(@.<|>) :: NExpr -> Text -> NExpr -> NExpr
@.<|> :: NExpr -> Text -> NExpr -> NExpr
(@.<|>) NExpr
obj Text
name NExpr
alt = Maybe NExpr -> NExpr -> Text -> NExpr
getRefOrDefault (NExpr -> Maybe NExpr
forall (f :: * -> *) a. Applicative f => a -> f a
pure NExpr
alt ) NExpr
obj Text
name
infix 9 @.<|>
@@ :: NExpr -> NExpr -> NExpr
(@@) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NApp
infixl 8 @@
$++ :: NExpr -> NExpr -> NExpr
($++) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NConcat
infixr 7 $++
$* :: NExpr -> NExpr -> NExpr
($*) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NMult
infixl 6 $*
$/ :: NExpr -> NExpr -> NExpr
($/) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NDiv
infixl 6 $/
$+ :: NExpr -> NExpr -> NExpr
($+) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NPlus
infixl 5 $+
$- :: NExpr -> NExpr -> NExpr
($-) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NMinus
infixl 5 $-
$// :: NExpr -> NExpr -> NExpr
($//) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NUpdate
infixr 5 $//
$> :: NExpr -> NExpr -> NExpr
($>) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NGt
infix 4 $>
infix 4 $>=
$>= :: NExpr -> NExpr -> NExpr
($>=) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NGte
$<= :: NExpr -> NExpr -> NExpr
($<=) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NLte
infix 4 $<=
$< :: NExpr -> NExpr -> NExpr
($<) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NLt
infix 4 $<
$== :: NExpr -> NExpr -> NExpr
($==) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NEq
infix 3 $==
$!= :: NExpr -> NExpr -> NExpr
($!=) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NNEq
infix 3 $!=
$&& :: NExpr -> NExpr -> NExpr
($&&) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NAnd
infixl 2 $&&
$|| :: NExpr -> NExpr -> NExpr
($||) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NOr
infixl 2 $||
$-> :: NExpr -> NExpr -> NExpr
($->) = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2 NBinaryOp
NImpl
infix 1 $->
(==>) :: Params NExpr -> NExpr -> NExpr
==> :: Params NExpr -> NExpr -> NExpr
(==>) = Params NExpr -> NExpr -> NExpr
mkFunction
infixr 1 ==>
mkOper :: NUnaryOp -> NExpr -> NExpr
mkOper :: NUnaryOp -> NExpr -> NExpr
mkOper = NUnaryOp -> NExpr -> NExpr
mkOp
mkOper2 :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkOper2 :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkOper2 = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2
mkBinop :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkBinop :: NBinaryOp -> NExpr -> NExpr -> NExpr
mkBinop = NBinaryOp -> NExpr -> NExpr -> NExpr
mkOp2
mkParamset :: [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkParamset :: [(Text, Maybe NExpr)] -> Bool -> Params NExpr
mkParamset [(Text, Maybe NExpr)]
params Bool
variadic = Maybe VarName -> Variadic -> ParamSet NExpr -> Params NExpr
forall r. Maybe VarName -> Variadic -> ParamSet r -> Params r
ParamSet Maybe VarName
forall a. Maybe a
Nothing (Variadic
Variadic Variadic -> Bool -> Variadic
forall a. Monoid a => a -> Bool -> a
`whenTrue` Bool
variadic) ([(Text, Maybe NExpr)] -> ParamSet NExpr
coerce [(Text, Maybe NExpr)]
params)