{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module GHC.Util.W (
W(..)
, wrap, unwrap
, eqLoc', eqNoLoc', eqNoLocLists') where
import Outputable
import SrcLoc
import GHC.Util.DynFlags
import GHC.Util.SrcLoc
import Data.Function
import Data.Data
import Data.Generics.Uniplate.Data ()
newtype W a = W a deriving Outputable
wToStr :: Outputable a => W a -> String
wToStr (W e) = showPpr baseDynFlags e
instance Outputable a => Eq (W a) where (==) a b = wToStr a == wToStr b
instance Outputable a => Ord (W a) where compare = compare `on` wToStr
instance Outputable a => Show (W a) where show = wToStr
wrap :: a -> W a
wrap = W
unwrap :: W a -> a
unwrap (W x) = x
eqLoc' :: Outputable a => a -> a -> Bool
eqLoc' a b = wrap a == wrap b
eqNoLoc' :: (Data a, Outputable a, HasSrcSpan a) => a -> a -> Bool
eqNoLoc' a b = wrap (stripLocs' a) == wrap (stripLocs' b)
eqNoLocLists' :: (Data a, Outputable a, HasSrcSpan a) => [a] -> [a] -> Bool
eqNoLocLists' as bs = length as == length bs && all (uncurry eqNoLoc') (zip as bs)