HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulehnix-0.17.0Haskell2010

Nix.Value

The core of the type system, Nix language values

Contents
  1. NValueF: Base functor (F)
  2. Eq
  3. Eq1
  4. Show
  5. Foldable
  6. Traversable
  7. Monad
  8. MonadTrans
  9. MonadTransUnlift
  10. Utils
  11. NValue': forming the (F(A))
  12. Show1
  13. Traversable
  14. Profunctor
  15. Free
  16. Utils
  17. Monad
  18. MonadTrans
  19. MonadTransUnlift
  20. Bijective Hask subcategory - NValue'
  21. F: Hask subcategory - NValue'
  22. NValue: Nix language values
  23. Free
  24. Utils
  25. MonadTrans
  26. MonadTransUnlift
  27. Methods F: Hask → NValue
  28. F: Evaluation -> NValue
  29. TStringContext
  30. ValueType
  31. ValueFrame
  32. MonadDataContext
  33. MonadDataErrorContext
  34. instance Eq NValue'
  35. instance Eq1 NValue'
  36. NValueF traversals, getter & setters
Synopsis
  • Packagehnix-0.17.0
  • Exports61
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceValue.hs

NValueF: Base functor (F)

datadata NValueF p (m :: Type -> Type) r

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 NAtom
  • NVStrF NixString

    A string has a value and a context, which can be used to record what a string has been build from

  • NVPathF Path
  • NVListF [r]
  • NVSetF PositionSet (AttrSet r)

    Quite frequently actions/processing happens with values (for example - forcing of values & recreation of the monad), but SourcePos does 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, …

Eq

Eq1

Show

Foldable

Traversable

Monad

valuebindNValueF
  1. :: (Monad m, Monad n)
  2. => (forall x. n x -> m x)

    Transform n into m.

  3. -> (a -> n b)

    A Kleisli arrow (see Kleisli & Kleisli catagory).

  4. -> NValueF p m a

    Unfixed (openly recursive) value of an embedded Nix language.

  5. -> n (NValueF p m b)

    An implementation of transform (f =<< x) for embedded Nix language values.

bind

MonadTrans

MonadTransUnlift

Utils

NValue': forming the (F(A))

newtypenewtype NValue' t (f :: Type -> Type) (m :: Type -> Type) a

At the time of constructor, the expected arguments to closures are values that may contain thunks. The type of such thunks are fixed at that time.

Constructors

  • NValue'
    • _nValue :: f (NValueF (NValue t f m) m a)

      Applying F-algebra Base functor data type (NValueF) to the F-algebra carrier (NValue), forming the F(A)-> A ).

Instances63HasCitations, HasCitations1, Scoped, MonadValue, MonadValueF, MonadThunk, …

Show1

Traversable

Profunctor

Free

Utils

Monad

MonadTrans

MonadTransUnlift

Bijective Hask subcategory - NValue'

F: Hask subcategory - NValue'

F: Hask - NValue'

Since Haskell and Nix are both recursive purely functional lazy languages. And since recursion-schemes. It is possible to create a direct functor between the Hask and Nix categories. Or make Nix a DLS language of Haskell, embed it into a Hask, if you would like. Of course, we mean: pick Hask subcategory and form Nix Category from it. Take subcategory of Hask, and by applying functor to it - have a Nix Category. Wouldn't it be cool and fast?

In fact - it is what we do here.

Since it is a proper way of scientific implementation, we would eventually form a lawful functor.

Module pattens use language PatternSynonyms: bidirectional synonyms (<-), and ViewPatterns: (->) at the same time. ViewPatterns Control.Comonad.extract extracts from the NValue (Free (NValueF a)) the NValueF a. Which is NValueF p m r. Since it extracted from the NValue, which is formed by (F a -> a) F a in the first place. So NValueF p m r which is extracted here, internally holds the next NValue.

Facts of bijection between Hask subcategory objects and Nix objects, and between Hask subcategory morphisms and Nix morphisms are seen blow:

patternpattern NVNull' :: NVConstraint w => NValue' t w m a

Using of Nulls is generally discouraged (in programming language design et al.), but, if you need it.

NValue: Nix language values

typetype NValue t (f :: Type -> Type) (m :: Type -> Type) = Free (NValue' t f m) t

'NValue t f m' is a value in head normal form (it means only the tip of it has been evaluated to the normal form, while the rest of it is in lazy not evaluated form (thunk), this known as WHNF).

An action 'm (NValue t f m)' is a pending evaluation that has yet to be performed.

An t is either: * a pending evaluation. * a value in head normal form.

The Free structure is used here to represent the possibility that Nix language allows cycles that may appear during normalization.

Free

Utils

MonadTrans

MonadTransUnlift

Methods F: Hask → NValue

F: Hask → NValue

The morphisms of the functor Hask → NValue. Continuation of the mantra: Nix.Value#mantra

F: Evaluation -> NValue

TStringContext

ValueType

ValueFrame

datadata ValueFrame t (f :: Type -> Type) (m :: Type -> Type)
#
Instances2Show, Exception

MonadDataContext

MonadDataErrorContext

instance Eq NValue'

instance Eq1 NValue'

NValueF traversals, getter & setters