1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.ReifySpec where
import qualified Data.List as L
import Data.Reify
import Prelude ()
import Prelude.Compat
import Test.Hspec
main :: IO ()
main = hspec spec
spec :: Spec
spec = parallel $
describe "reifyGraph" $
it "should produce a Graph with unique key-value pairs" $ do -- #11
g <- reifyGraph s1
nubGraph g `shouldBe` g
data State = State Char [State]
deriving (Eq, Show)
data StateDeRef r = StateDeRef Char [r]
deriving (Eq, Show)
s1, s2, s3 :: State
s1 = State 'a' [s2,s3]
s2 = State 'b' [s1,s2]
s3 = State 'c' [s2,s1]
instance MuRef State where
type DeRef State = StateDeRef
mapDeRef f (State a tr) = StateDeRef a <$> traverse f tr
nubGraph :: Eq (e Unique) => Graph e -> Graph e
nubGraph (Graph netlist start) = Graph (L.nub netlist) start
deriving instance Eq (e Unique) => Eq (Graph e)
|