Types

This chapter clarifies all types.

To Pickup the overview more quickly they can be viewed in the following list.

Every decision and further specification are explained in the corresponding sub-chapters respectively.

List of all Types

Primitives


TypeDescription
BoolA value of type boolean can be either true or false
IntTODO: The classical integer type with 32-bit or 64-bit depending on the current system?
FloatA float with 64 bits?
StringA string of any unicode characters
PathPath referencing a location or a file. With no assumptions on the existence of that
NullThe value null

The Any type

The Any type is often used to explicitly allow arbitrary values. However, the Any type is complex and doesn't add much value to a type system. Instead, we should use type variables whenever possible.

Interestingly there are two different Any types:

e.g. If we look at CUE-lang (which is also inspired by nix)

CUE defines the values bottom, or error, (denoted |) that is an instance of all types and top, or any, (denoted _) of which all types are an instance.

  • TOP any all types are an instance of that. You can imagine it as the TOP-most set, that includes every type. But no value has that type.

  • Bottom any which is an instance of all types. This is kind of the imaginary value that has the any type. Still, doesn't contain any value. Which could also be denoted: Never or Empty Type it is a type that is the subtype of any type.

The following is a nice quote from the Typescript world

The any type is so dangerous because it exists outside of the type tree. It is both a top and bottom type. Everything can be assigned to it and it can be assigned to everything else. ...

Complex

T, U, ...; are placeholders for any types, those MUST be specifically declared on usage


AnnotationTypeDescriptionchapter
[T]ListList of elements with type T eachList
{N::T}AttrSetAttrSet where member N references value of type TAttrSet
T->ULambdaA function that takes a single argument of type T and returns a value of type Ulambda

More details how to use complex types in the corresponding chapters

Composed


TypeCompositionDescription
NumberInt {or} FloatThe Number is either of type Int or of type Float
Any?There is no Any type and it is explicitly prohibited to use the Any type. Use type variables instead if you want to allow variable type signatures.
StorePathPathThe StorePath is just a meaningful alias of the type Path
Derivation{ ... }TODO: Derivation is just a special AttrSet.
PackageDerivation {or} {...}TODO: Package is either a Derivation or a special AttrSet with name xy in it.

used operators are defined in the operators chapter