Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value: Organization & Docs #842

Merged
merged 7 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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