{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -Wno-missing-pattern-synonym-signatures #-}

module Nix.Value.Equal where

import           Prelude                 hiding ( Comparison
                                                , force
                                                )
import           Nix.Utils
import           Control.Comonad                ( Comonad(extract))
import           Control.Monad.Free             ( Free(Pure,Free) )
import           Control.Monad.Trans.Except     ( throwE )
import           Data.Semialign                 ( Align
                                                , Semialign(align)
                                                )
import qualified Data.HashMap.Lazy             as HashMap.Lazy
import           Data.These                     ( These(These) )
import           Nix.Atoms
import           Nix.Frames
import           Nix.String
import           Nix.Thunk
import           Nix.Value

checkComparable
  :: ( Framed e m
     , MonadDataErrorContext t f m
     )
  => NValue t f m
  -> NValue t f m
  -> m ()
checkComparable :: NValue t f m -> NValue t f m -> m ()
checkComparable NValue t f m
x NValue t f m
y =
  case (NValue t f m
x, NValue t f m
y) of
    (NVConstant (NFloat Float
_), NVConstant (NInt   Integer
_)) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NVConstant (NInt   Integer
_), NVConstant (NFloat Float
_)) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NVConstant (NInt   Integer
_), NVConstant (NInt   Integer
_)) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NVConstant (NFloat Float
_), NVConstant (NFloat Float
_)) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NVStr       NixString
_        , NVStr       NixString
_        ) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NVPath      FilePath
_        , NVPath      FilePath
_        ) -> m ()
forall (f :: * -> *). Applicative f => f ()
pass
    (NValue t f m, NValue t f m)
_                                              -> ValueFrame t f m -> m ()
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m ()) -> ValueFrame t f m -> m ()
forall a b. (a -> b) -> a -> b
$ NValue t f m -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
NValue t f m -> NValue t f m -> ValueFrame t f m
Comparison NValue t f m
x NValue t f m
y

-- | Checks whether two containers are equal, using the given item equality
--   predicate. If there are any item slots that don't match between the two
--   containers, the result will be @False@.
alignEqM
  :: (Align f, Traversable f, Monad m)
  => (a -> b -> m Bool)
  -> f a
  -> f b
  -> m Bool
alignEqM :: (a -> b -> m Bool) -> f a -> f b -> m Bool
alignEqM a -> b -> m Bool
eq f a
fa f b
fb =
  (Either () () -> Bool) -> m (Either () ()) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
    Either () () -> Bool
forall a b. Either a b -> Bool
isRight
    (m (Either () ()) -> m Bool) -> m (Either () ()) -> m Bool
forall a b. (a -> b) -> a -> b
$ ExceptT () m () -> m (Either () ())
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT () m () -> m (Either () ()))
-> ExceptT () m () -> m (Either () ())
forall a b. (a -> b) -> a -> b
$
      do
        f (a, b)
pairs <-
          (These a b -> ExceptT () m (a, b))
-> f (These a b) -> ExceptT () m (f (a, b))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
            (\case
              These a
a b
b -> (a, b) -> ExceptT () m (a, b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
a, b
b)
              These a b
_         -> () -> ExceptT () m (a, b)
forall (m :: * -> *) e a. Monad m => e -> ExceptT e m a
throwE ()
            )
            (f a -> f b -> f (These a b)
forall (f :: * -> *) a b.
Semialign f =>
f a -> f b -> f (These a b)
Data.Semialign.align f a
fa f b
fb)
        ((a, b) -> ExceptT () m ()) -> f (a, b) -> ExceptT () m ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (\ (a
a, b
b) -> Bool -> ExceptT () m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> ExceptT () m ()) -> ExceptT () m Bool -> ExceptT () m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m Bool -> ExceptT () m Bool
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> b -> m Bool
eq a
a b
b)) f (a, b)
pairs

alignEq :: (Align f, Traversable f) => (a -> b -> Bool) -> f a -> f b -> Bool
alignEq :: (a -> b -> Bool) -> f a -> f b -> Bool
alignEq a -> b -> Bool
eq f a
fa f b
fb = Identity Bool -> Bool
forall a. Identity a -> a
runIdentity (Identity Bool -> Bool) -> Identity Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (a -> b -> Identity Bool) -> f a -> f b -> Identity Bool
forall (f :: * -> *) (m :: * -> *) a b.
(Align f, Traversable f, Monad m) =>
(a -> b -> m Bool) -> f a -> f b -> m Bool
alignEqM (\a
x b
y -> Bool -> Identity Bool
forall a. a -> Identity a
Identity (a -> b -> Bool
eq a
x b
y)) f a
fa f b
fb

isDerivationM
  :: Monad m
  => ( t
     -> m (Maybe NixString)
     )
  -> AttrSet t
  -> m Bool
isDerivationM :: (t -> m (Maybe NixString)) -> AttrSet t -> m Bool
isDerivationM t -> m (Maybe NixString)
f AttrSet t
m =
  m Bool -> (t -> m Bool) -> Maybe t -> m Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
    (Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False)
    (\ t
t ->
      Bool -> (NixString -> Bool) -> Maybe NixString -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
        -- We should probably really make sure the context is empty here
        -- but the C++ implementation ignores it.
        Bool
False
        (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
(==) Text
"derivation" (Text -> Bool) -> (NixString -> Text) -> NixString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> Text
stringIgnoreContext)
        (Maybe NixString -> Bool) -> m (Maybe NixString) -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> m (Maybe NixString)
f t
t
    )
    (Text -> AttrSet t -> Maybe t
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.Lazy.lookup Text
"type" AttrSet t
m)

isDerivation
  :: Monad m
  => ( t
     -> Maybe NixString
     )
  -> AttrSet t
  -> Bool
isDerivation :: (t -> Maybe NixString) -> AttrSet t -> Bool
isDerivation t -> Maybe NixString
f = Identity Bool -> Bool
forall a. Identity a -> a
runIdentity (Identity Bool -> Bool)
-> (AttrSet t -> Identity Bool) -> AttrSet t -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t -> Identity (Maybe NixString)) -> AttrSet t -> Identity Bool
forall (m :: * -> *) t.
Monad m =>
(t -> m (Maybe NixString)) -> AttrSet t -> m Bool
isDerivationM (Maybe NixString -> Identity (Maybe NixString)
forall a. a -> Identity a
Identity (Maybe NixString -> Identity (Maybe NixString))
-> (t -> Maybe NixString) -> t -> Identity (Maybe NixString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Maybe NixString
f)

valueFEqM
  :: Monad n
  => (  AttrSet a
     -> AttrSet a
     -> n Bool
     )
  -> (  a
     -> a
     -> n Bool
     )
  -> NValueF p m a
  -> NValueF p m a
  -> n Bool
valueFEqM :: (AttrSet a -> AttrSet a -> n Bool)
-> (a -> a -> n Bool) -> NValueF p m a -> NValueF p m a -> n Bool
valueFEqM AttrSet a -> AttrSet a -> n Bool
attrsEq a -> a -> n Bool
eq =
  ((NValueF p m a, NValueF p m a) -> n Bool)
-> NValueF p m a -> NValueF p m a -> n Bool
forall a b c. ((a, b) -> c) -> a -> b -> c
curry (((NValueF p m a, NValueF p m a) -> n Bool)
 -> NValueF p m a -> NValueF p m a -> n Bool)
-> ((NValueF p m a, NValueF p m a) -> n Bool)
-> NValueF p m a
-> NValueF p m a
-> n Bool
forall a b. (a -> b) -> a -> b
$
    \case
      (NVConstantF (NFloat Float
x), NVConstantF (NInt   Integer
y)) -> Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> n Bool) -> Bool -> n Bool
forall a b. (a -> b) -> a -> b
$             Float
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y
      (NVConstantF (NInt   Integer
x), NVConstantF (NFloat Float
y)) -> Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> n Bool) -> Bool -> n Bool
forall a b. (a -> b) -> a -> b
$ Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Float
y
      (NVConstantF NAtom
lc        , NVConstantF NAtom
rc        ) -> Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> n Bool) -> Bool -> n Bool
forall a b. (a -> b) -> a -> b
$            NAtom
lc NAtom -> NAtom -> Bool
forall a. Eq a => a -> a -> Bool
== NAtom
rc
      (NVStrF      NixString
ls        , NVStrF      NixString
rs        ) -> Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> n Bool) -> Bool -> n Bool
forall a b. (a -> b) -> a -> b
$  (\ NixString -> Text
i -> NixString -> Text
i NixString
ls Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== NixString -> Text
i NixString
rs) NixString -> Text
stringIgnoreContext
      (NVListF     [a]
ls        , NVListF     [a]
rs        ) ->          (a -> a -> n Bool) -> [a] -> [a] -> n Bool
forall (f :: * -> *) (m :: * -> *) a b.
(Align f, Traversable f, Monad m) =>
(a -> b -> m Bool) -> f a -> f b -> m Bool
alignEqM a -> a -> n Bool
eq [a]
ls [a]
rs
      (NVSetF      AttrSet a
lm AttrSet SourcePos
_      , NVSetF      AttrSet a
rm AttrSet SourcePos
_      ) ->          AttrSet a -> AttrSet a -> n Bool
attrsEq AttrSet a
lm AttrSet a
rm
      (NVPathF     FilePath
lp        , NVPathF     FilePath
rp        ) ->             Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> n Bool) -> Bool -> n Bool
forall a b. (a -> b) -> a -> b
$ FilePath
lp FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
rp
      (NValueF p m a, NValueF p m a)
_                                                -> Bool -> n Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False

valueFEq
  :: (AttrSet a -> AttrSet a -> Bool)
  -> (a -> a -> Bool)
  -> NValueF p m a
  -> NValueF p m a
  -> Bool
valueFEq :: (AttrSet a -> AttrSet a -> Bool)
-> (a -> a -> Bool) -> NValueF p m a -> NValueF p m a -> Bool
valueFEq AttrSet a -> AttrSet a -> Bool
attrsEq a -> a -> Bool
eq NValueF p m a
x NValueF p m a
y =
  Identity Bool -> Bool
forall a. Identity a -> a
runIdentity (Identity Bool -> Bool) -> Identity Bool -> Bool
forall a b. (a -> b) -> a -> b
$
    (AttrSet a -> AttrSet a -> Identity Bool)
-> (a -> a -> Identity Bool)
-> NValueF p m a
-> NValueF p m a
-> Identity Bool
forall (n :: * -> *) a p (m :: * -> *).
Monad n =>
(AttrSet a -> AttrSet a -> n Bool)
-> (a -> a -> n Bool) -> NValueF p m a -> NValueF p m a -> n Bool
valueFEqM
      (\AttrSet a
x' AttrSet a
y' -> Bool -> Identity Bool
forall a. a -> Identity a
Identity (Bool -> Identity Bool) -> Bool -> Identity Bool
forall a b. (a -> b) -> a -> b
$ AttrSet a -> AttrSet a -> Bool
attrsEq AttrSet a
x' AttrSet a
y')
      (\a
x' a
y' -> Bool -> Identity Bool
forall a. a -> Identity a
Identity (Bool -> Identity Bool) -> Bool -> Identity Bool
forall a b. (a -> b) -> a -> b
$ a -> a -> Bool
eq a
x' a
y')
      NValueF p m a
x
      NValueF p m a
y

compareAttrSetsM
  :: Monad m
  => (t -> m (Maybe NixString))
  -> (t -> t -> m Bool)
  -> AttrSet t
  -> AttrSet t
  -> m Bool
compareAttrSetsM :: (t -> m (Maybe NixString))
-> (t -> t -> m Bool) -> AttrSet t -> AttrSet t -> m Bool
compareAttrSetsM t -> m (Maybe NixString)
f t -> t -> m Bool
eq AttrSet t
lm AttrSet t
rm =
  do
    Bool
l <- (t -> m (Maybe NixString)) -> AttrSet t -> m Bool
forall (m :: * -> *) t.
Monad m =>
(t -> m (Maybe NixString)) -> AttrSet t -> m Bool
isDerivationM t -> m (Maybe NixString)
f AttrSet t
lm
    m Bool -> m Bool -> Bool -> m Bool
forall a. a -> a -> Bool -> a
bool
      m Bool
compareAttrs
      (do
        Bool
r <- (t -> m (Maybe NixString)) -> AttrSet t -> m Bool
forall (m :: * -> *) t.
Monad m =>
(t -> m (Maybe NixString)) -> AttrSet t -> m Bool
isDerivationM t -> m (Maybe NixString)
f AttrSet t
rm
        case Bool
r of
          Bool
True
            | Just t
lp <- Text -> AttrSet t -> Maybe t
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.Lazy.lookup Text
"outPath" AttrSet t
lm,
              Just t
rp <- Text -> AttrSet t -> Maybe t
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.Lazy.lookup Text
"outPath" AttrSet t
rm -> t -> t -> m Bool
eq t
lp t
rp
          Bool
_ -> m Bool
compareAttrs
      )
      Bool
l
 where
  compareAttrs :: m Bool
compareAttrs = (t -> t -> m Bool) -> AttrSet t -> AttrSet t -> m Bool
forall (f :: * -> *) (m :: * -> *) a b.
(Align f, Traversable f, Monad m) =>
(a -> b -> m Bool) -> f a -> f b -> m Bool
alignEqM t -> t -> m Bool
eq AttrSet t
lm AttrSet t
rm

compareAttrSets
  :: (t -> Maybe NixString)
  -> (t -> t -> Bool)
  -> AttrSet t
  -> AttrSet t
  -> Bool
compareAttrSets :: (t -> Maybe NixString)
-> (t -> t -> Bool) -> AttrSet t -> AttrSet t -> Bool
compareAttrSets t -> Maybe NixString
f t -> t -> Bool
eq AttrSet t
lm AttrSet t
rm = Identity Bool -> Bool
forall a. Identity a -> a
runIdentity
  (Identity Bool -> Bool) -> Identity Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (t -> Identity (Maybe NixString))
-> (t -> t -> Identity Bool)
-> AttrSet t
-> AttrSet t
-> Identity Bool
forall (m :: * -> *) t.
Monad m =>
(t -> m (Maybe NixString))
-> (t -> t -> m Bool) -> AttrSet t -> AttrSet t -> m Bool
compareAttrSetsM (Maybe NixString -> Identity (Maybe NixString)
forall a. a -> Identity a
Identity (Maybe NixString -> Identity (Maybe NixString))
-> (t -> Maybe NixString) -> t -> Identity (Maybe NixString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> Maybe NixString
f) (\t
x t
y -> Bool -> Identity Bool
forall a. a -> Identity a
Identity (Bool -> Identity Bool) -> Bool -> Identity Bool
forall a b. (a -> b) -> a -> b
$ t -> t -> Bool
eq t
x t
y) AttrSet t
lm AttrSet t
rm

valueEqM
  :: (MonadThunk t m (NValue t f m), Comonad f)
  => NValue t f m
  -> NValue t f m
  -> m Bool
valueEqM :: NValue t f m -> NValue t f m -> m Bool
valueEqM (  Pure t
x) (  Pure t
y) = t -> t -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
t -> t -> m Bool
thunkEqM t
x t
y
valueEqM (  Pure t
x) y :: NValue t f m
y@(Free NValue' t f m (NValue t f m)
_) = t -> t -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
t -> t -> m Bool
thunkEqM t
x (t -> m Bool) -> m t -> m Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m (NValue t f m) -> m t
forall t (m :: * -> *) a. MonadThunk t m a => m a -> m t
thunk (NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
y)
valueEqM x :: NValue t f m
x@(Free NValue' t f m (NValue t f m)
_) (  Pure t
y) = (t -> t -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
t -> t -> m Bool
`thunkEqM` t
y) (t -> m Bool) -> m t -> m Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m (NValue t f m) -> m t
forall t (m :: * -> *) a. MonadThunk t m a => m a -> m t
thunk (NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
x)
valueEqM (Free (NValue' (f (NValueF (NValue t f m) m (NValue t f m))
-> NValueF (NValue t f m) m (NValue t f m)
forall (w :: * -> *) a. Comonad w => w a -> a
extract -> NValueF (NValue t f m) m (NValue t f m)
x))) (Free (NValue' (f (NValueF (NValue t f m) m (NValue t f m))
-> NValueF (NValue t f m) m (NValue t f m)
forall (w :: * -> *) a. Comonad w => w a -> a
extract -> NValueF (NValue t f m) m (NValue t f m)
y))) =
  (AttrSet (NValue t f m) -> AttrSet (NValue t f m) -> m Bool)
-> (NValue t f m -> NValue t f m -> m Bool)
-> NValueF (NValue t f m) m (NValue t f m)
-> NValueF (NValue t f m) m (NValue t f m)
-> m Bool
forall (n :: * -> *) a p (m :: * -> *).
Monad n =>
(AttrSet a -> AttrSet a -> n Bool)
-> (a -> a -> n Bool) -> NValueF p m a -> NValueF p m a -> n Bool
valueFEqM
    ((NValue t f m -> m (Maybe NixString))
-> (NValue t f m -> NValue t f m -> m Bool)
-> AttrSet (NValue t f m)
-> AttrSet (NValue t f m)
-> m Bool
forall (m :: * -> *) t.
Monad m =>
(t -> m (Maybe NixString))
-> (t -> t -> m Bool) -> AttrSet t -> AttrSet t -> m Bool
compareAttrSetsM NValue t f m -> m (Maybe NixString)
forall t (m :: * -> *).
Free (NValue' t f m) t -> m (Maybe NixString)
f NValue t f m -> NValue t f m -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
NValue t f m -> NValue t f m -> m Bool
valueEqM)
    NValue t f m -> NValue t f m -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
NValue t f m -> NValue t f m -> m Bool
valueEqM
    NValueF (NValue t f m) m (NValue t f m)
x
    NValueF (NValue t f m) m (NValue t f m)
y
 where
  f :: Free (NValue' t f m) t -> m (Maybe NixString)
f =
    (t -> m (Maybe NixString))
-> (NValue' t f m (Free (NValue' t f m) t) -> m (Maybe NixString))
-> Free (NValue' t f m) t
-> m (Maybe NixString)
forall a b (f :: * -> *).
(a -> b) -> (f (Free f a) -> b) -> Free f a -> b
free
      (Maybe NixString -> m (Maybe NixString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe NixString -> m (Maybe NixString))
-> (NValue t f m -> Maybe NixString)
-> NValue t f m
-> m (Maybe NixString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        (\case
          NVStr NixString
s -> NixString -> Maybe NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure NixString
s
          NValue t f m
_       -> Maybe NixString
forall a. Monoid a => a
mempty
        ) (NValue t f m -> m (Maybe NixString))
-> (t -> m (NValue t f m)) -> t -> m (Maybe NixString)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force
      )
      (Maybe NixString -> m (Maybe NixString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe NixString -> m (Maybe NixString))
-> (NValue' t f m (Free (NValue' t f m) t) -> Maybe NixString)
-> NValue' t f m (Free (NValue' t f m) t)
-> m (Maybe NixString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
        \case
          NVStr' NixString
s -> NixString -> Maybe NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure NixString
s
          NValue' t f m (Free (NValue' t f m) t)
_        -> Maybe NixString
forall a. Monoid a => a
mempty
      )

thunkEqM :: (MonadThunk t m (NValue t f m), Comonad f) => t -> t -> m Bool
thunkEqM :: t -> t -> m Bool
thunkEqM t
lt t
rt =
  do
    NValue t f m
lv <- t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force t
lt
    NValue t f m
rv <- t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force t
rt

    let
      unsafePtrEq :: m Bool
unsafePtrEq =
        case (t
lt, t
rt) of
          (t -> ThunkId m
forall t (m :: * -> *) a. MonadThunk t m a => t -> ThunkId m
thunkId -> ThunkId m
lid, t -> ThunkId m
forall t (m :: * -> *) a. MonadThunk t m a => t -> ThunkId m
thunkId -> ThunkId m
rid) | ThunkId m
lid ThunkId m -> ThunkId m -> Bool
forall a. Eq a => a -> a -> Bool
== ThunkId m
rid -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
          (t, t)
_                                             -> NValue t f m -> NValue t f m -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
NValue t f m -> NValue t f m -> m Bool
valueEqM NValue t f m
lv NValue t f m
rv

    case (NValue t f m
lv, NValue t f m
rv) of
      (NVClosure Params ()
_ NValue t f m -> m (NValue t f m)
_, NVClosure Params ()
_ NValue t f m -> m (NValue t f m)
_) -> m Bool
unsafePtrEq
      (NVList [NValue t f m]
_     , NVList [NValue t f m]
_     ) -> m Bool
unsafePtrEq
      (NVSet AttrSet (NValue t f m)
_ AttrSet SourcePos
_    , NVSet AttrSet (NValue t f m)
_ AttrSet SourcePos
_    ) -> m Bool
unsafePtrEq
      (NValue t f m, NValue t f m)
_                              -> NValue t f m -> NValue t f m -> m Bool
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
NValue t f m -> NValue t f m -> m Bool
valueEqM NValue t f m
lv NValue t f m
rv