Skip to content

Commit

Permalink
Merge #842: Value: Organization & Docs; Atom: Organization & Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Latukha authored Feb 18, 2021
2 parents 803af1b + 1f90760 commit 9fb1df4
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 144 deletions.
42 changes: 31 additions & 11 deletions src/Nix/Atoms.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,33 @@
module Nix.Atoms where

#ifdef MIN_VERSION_serialise
import Codec.Serialise
import Codec.Serialise ( Serialise )
#endif
import Control.DeepSeq
import Data.Data

import Control.DeepSeq ( NFData )
import Data.Data ( Typeable
, Data)
import Data.Fixed ( mod' )
import Data.Hashable
import Data.Hashable ( Hashable )
import Data.Text ( Text
, pack
)
import GHC.Generics
import GHC.Generics ( Generic )
import Data.Binary ( Binary )
import Data.Aeson.Types ( FromJSON, ToJSON )
import Data.Aeson.Types ( FromJSON
, ToJSON
)

-- | Atoms are values that evaluate to themselves. This means that
-- | Atoms are values that evaluate to themselves.
-- In other words - this is a constructors that are literals in Nix.
-- This means that
-- they appear in both the parsed AST (in the form of literals) and
-- the evaluated form.
-- the evaluated form as themselves.
-- Once HNix parsed or evaluated into atom - that is a literal
-- further after, for any further evaluation it is in all cases stays
-- constantly itself.
-- "atom", Ancient Greek \( atomos \) - "indivisible" particle,
-- indivisible expression.
data NAtom
-- | An URI like @https://example.com@.
= NURI Text
Expand All @@ -35,8 +46,17 @@ data NAtom
| NBool Bool
-- | Null values. There's only one of this variant: @null@.
| NNull
deriving (Eq, Ord, Generic, Typeable, Data, Show, Read, NFData,
Hashable)
deriving
( Eq
, Ord
, Generic
, Typeable
, Data
, Show
, Read
, NFData
, Hashable
)

#ifdef MIN_VERSION_serialise
instance Serialise NAtom
Expand All @@ -46,7 +66,7 @@ instance Binary NAtom
instance ToJSON NAtom
instance FromJSON NAtom

-- | Translate an atom into its nix representation.
-- | Translate an atom into its Nix representation.
atomText :: NAtom -> Text
atomText (NURI t) = t
atomText (NInt i) = pack (show i)
Expand Down
Loading

0 comments on commit 9fb1df4

Please sign in to comment.