Skip to content

Commit c183989

Browse files
committed
Convert: Deeper: reduce singleton accessor in favour of the coerce
coerse works & reads intuitively. Currently because of the size & a lot of type imports to modules, and maybe because of recursivity of data types - GHC needs type signature help. But in the future it should improve & it makes code more understandable to the reader.
1 parent 07caac2 commit c183989

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/Nix/Builtins.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ substringNix start len str =
730730
attrNamesNix
731731
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
732732
attrNamesNix =
733-
(fmap getDeeper . toValue . fmap makeNixStringWithoutContext . sort . M.keys)
733+
(fmap (coerce :: CoerceDeeperToNValue t f m) . toValue . fmap makeNixStringWithoutContext . sort . M.keys)
734734
<=< fromValue @(AttrSet (NValue t f m))
735735

736736
attrValuesNix
@@ -1441,7 +1441,7 @@ readDirNix nvpath =
14411441
detectFileTypes
14421442
items
14431443

1444-
getDeeper <$> toValue (M.fromList itemsWithTypes)
1444+
(coerce :: CoerceDeeperToNValue t f m) <$> toValue (M.fromList itemsWithTypes)
14451445

14461446
fromJSONNix
14471447
:: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)

src/Nix/Convert.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ import Nix.Frames
2727
import Nix.String
2828
import Nix.Value
2929
import Nix.Value.Monad
30-
import Nix.Thunk
30+
import Nix.Thunk ( MonadThunk(force) )
3131
import Nix.Utils
3232

33-
newtype Deeper a = Deeper { getDeeper :: a }
33+
newtype Deeper a = Deeper a
3434
deriving (Typeable, Functor, Foldable, Traversable)
3535

36+
type CoerceDeeperToNValue t f m = Deeper (NValue t f m) -> NValue t f m
37+
type CoerceDeeperToNValue' t f m = Deeper (NValue' t f m (NValue t f m)) -> NValue' t f m (NValue t f m)
38+
3639
{-
3740
3841
IMPORTANT NOTE
@@ -83,7 +86,7 @@ fromMayToDeeperValue t v =
8386
do
8487
v' <- fromValueMay v
8588
maybe
86-
(throwError $ Expectation @t @f @m t $ Free $ getDeeper v)
89+
(throwError $ Expectation @t @f @m t $ Free $ (coerce :: CoerceDeeperToNValue' t f m) v)
8790
pure
8891
v'
8992

@@ -313,8 +316,8 @@ instance ( Convertible e t f m
313316
, FromValue a m (NValue' t f m (NValue t f m))
314317
)
315318
=> FromValue a m (Deeper (NValue' t f m (NValue t f m))) where
316-
fromValueMay = fromValueMay . getDeeper
317-
fromValue = fromValue . getDeeper
319+
fromValueMay = fromValueMay . (coerce :: CoerceDeeperToNValue' t f m)
320+
fromValue = fromValue . (coerce :: CoerceDeeperToNValue' t f m)
318321

319322

320323
-- * ToValue

0 commit comments

Comments
 (0)