An NValueF p m r represents all the possible types of Nix values.
Is is the base functor to form the Free monad of nix expressions.
The parameter r represents Nix values in their final form (NValue).
The parameter p represents exactly the same type, but is kept separate
or it would prevent NValueF from being a proper functor.
It is intended to be hard-coded to the same final type as r.
m is the monad in which evaluations will run.
An NValue' t f m a is a magic layer between NValueF and the Free monad construction.
It fixes the p parameter of NValueF to the final NValue type, making the
definition of NValue' and NValue depend on each other in a recursive
fashion.
It also introduces a f parameter for a custom functor that can be used
to wrap each intermediate value in the reduced expression tree.
This is where expression evaluations can store annotations and other
useful information.
t is not really used here, but is needed to type the (NValue t f m)
used to tie the knot of the p parameter in the inner NValueF.
a is will be an `NValue t f m` when NValue' functor is turned into a
Free monad.
'NValue t f m' is the most reduced form of a NExpr after evaluation is completed. It is a layer cake of NValueF base values, wrapped in the f functor and into the Free recursive construction.
Concretely, an NValue t f m can either be a thunk, representing a value
yet to be evaluated (Pure t), or a know value in WHNF
(Free (NValue' t f m (NValue t f m))) = (Free (f (NValueF NValue m NValue))
That is, a base value type, wrapped into the generic f
functor, and based on other NValue's, which can in turn be either thunks,
or more already WHNF evaluated values.
As an example, the value `[1]` will be represented as
Free (f (NVListF [ (Free (f (NVConstantF (NInt 1)))) ]))
Should this 1 be a laziy and yet unevaluated value, it would be represented as
Free (f (NVListF [ (Pure t) ]))
Where the t is evaluator dependant, and should contain anough information
to be evaluated to an NValue when needed. demand of force are used to
turn a potential thunk into a `m (NValue t f m)`.
Of course, trees can be much bigger.
The number of layers and type aliases for similar things is huge, so this module provides ViewPatterns for each NValueF constructor.
For example, the pattern NVStr' ns matches a NValue' containing an NVStrF, and bind that NVStrF to ns, ignoring the f functor inside. Similarly, the pattern NVStr ns (without prime mark) will match the inner NVstrF value inside an NValue. Of course, the patterns are declined for all the NValueF constructors. The non primed version also has an NVThunk t pattern to account for the possibility of an NValue to no be fully evaluated yet, as opposed to an NValue'.
Constructors
NVConstantF NAtomNVStrF NixStringA string has a value and a context, which can be used to record what a string has been build from
NVPathF PathNVListF [r]NVSetF PositionSet (AttrSet r)Quite frequently actions/processing happens with values (for example - forcing of values & recreation of the monad), but
SourcePosdoes not change then.NVClosureF (Params ()) (p -> m r)A function is a closed set of parameters representing the "call signature", used at application time to check the type of arguments passed to the function. Since it supports default values which may depend on other values within the final argument set, this dependency is represented as a set of pending evaluations. The arguments are finally normalized into a set which is passed to the function.
Note that 'm r' is being used here because effectively a function and its set of default arguments is "never fully evaluated". This enforces in the type that it must be re-evaluated for each call.
NVBuiltinF VarName (p -> m r)A builtin function is itself already in normal form. Also, it may or may not choose to evaluate its argument in the production of a result.
Instances7Functor, Foldable, Eq1, Eq, Show, Generic, …
Functor m => Functor (NValueF p m)Defined in hnix-0.17.0 · Nix.ValueFoldable (NValueF p m)Defined in hnix-0.17.0 · Nix.ValueFolds what the value is known to contain at time of fold.
Eq1 (NValueF p m)Defined in hnix-0.17.0 · Nix.ValueEq r => Eq (NValueF p m r)Defined in hnix-0.17.0 · Nix.ValueShow r => Show (NValueF p m r)Defined in hnix-0.17.0 · Nix.ValueGeneric (NValueF p m r)Defined in hnix-0.17.0 · Nix.Valuetype Rep (NValueF p m r) = D1 ('MetaDataDefined in hnix-0.17.0 · Nix.Value"NValueF"
"Nix.Value"
"hnix-0.17.0-Iy75YcImuzK7FD0KGfkLv7"
'False) ((C1 ('MetaCons"NVConstantF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NAtom)) :+: (C1 ('MetaCons"NVStrF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NixString)) :+: C1 ('MetaCons"NVPathF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Path)))) :+: ((C1 ('MetaCons"NVListF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [r])) :+: C1 ('MetaCons"NVSetF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 PositionSet) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (AttrSet r)))) :+: (C1 ('MetaCons"NVClosureF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Params ())) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (p -> m r))) :+: C1 ('MetaCons"NVBuiltinF"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 VarName) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (p -> m r))))))