Skip to content

Commit 291d2e0

Browse files
committed
Value: TStringContext: add instances {Semigroup, Monoid}
1 parent 5cb99c5 commit 291d2e0

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/Nix/Convert.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,18 @@ instance ( Convertible e t f m
205205
(M.lookup "outPath" s)
206206
_ -> stub
207207

208-
fromValue = fromMayToValue $ TString NoContext
208+
fromValue = fromMayToValue $ TString mempty
209209

210210
instance Convertible e t f m
211211
=> FromValue ByteString m (NValue' t f m (NValue t f m)) where
212212

213213
fromValueMay =
214214
pure .
215215
\case
216-
NVStr' ns -> encodeUtf8 <$> getStringNoContext ns
216+
NVStr' ns -> encodeUtf8 <$> getStringNoContext ns
217217
_ -> mempty
218218

219-
fromValue = fromMayToValue $ TString NoContext
220-
219+
fromValue = fromMayToValue $ TString mempty
221220

222221
newtype Path = Path FilePath
223222
deriving Show
@@ -229,8 +228,8 @@ instance ( Convertible e t f m
229228

230229
fromValueMay =
231230
\case
232-
NVPath' p -> pure $ pure $ Path p
233-
NVStr' ns -> pure $ Path . toString <$> getStringNoContext ns
231+
NVPath' p -> pure $ pure $ coerce p
232+
NVStr' ns -> pure $ coerce . toString <$> getStringNoContext ns
234233
NVSet' s _ ->
235234
maybe
236235
(pure Nothing)

src/Nix/String/Coerce.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,5 @@ coerceToString call ctsm clevel = go
116116
t
117117
(StringContext t DirectPath)
118118
where
119-
t = toText $ unStorePath sp
119+
t = toText @FilePath $ coerce sp
120120

src/Nix/Value.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ pattern NVBuiltin name f <- Free (NVBuiltin' name f)
706706
data TStringContext = NoContext | HasContext
707707
deriving Show
708708

709+
instance Semigroup TStringContext where
710+
(<>) HasContext _ = HasContext
711+
(<>) _ HasContext = HasContext
712+
(<>) _ _ = NoContext
713+
714+
715+
instance Monoid TStringContext where
716+
mempty = NoContext
717+
709718
-- * @ValueType@
710719

711720
data ValueType
@@ -728,15 +737,15 @@ valueType =
728737
\case
729738
NVConstantF a ->
730739
case a of
731-
NURI _ -> TString NoContext
740+
NURI _ -> TString mempty
732741
NInt _ -> TInt
733742
NFloat _ -> TFloat
734743
NBool _ -> TBool
735744
NNull -> TNull
736745
NVStrF ns ->
737746
TString $
738747
bool
739-
NoContext
748+
mempty
740749
HasContext
741750
(stringHasContext ns)
742751
NVListF{} -> TList

0 commit comments

Comments
 (0)