{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-|
   Module for the definition of 'EClass'.
-}
module Data.Equality.Graph.Classes
    ( module Data.Equality.Graph.Classes
    , module Data.Equality.Graph.Classes.Id
    ) where

import qualified Data.Set as S

import Data.Functor.Classes

import Data.Equality.Graph.Classes.Id
import Data.Equality.Graph.Nodes

import Data.Equality.Utils.SizedList

import Data.Equality.Analysis

-- | An e-class (an equivalence class of terms) of a language @l@.
--
-- Intuitively, an e-graph is a set of equivalence classes (e-classes). Each
-- e-class is a set of e-nodes representing equivalent terms from a given
-- language, and an e-node is a function symbol paired with a list of children
-- e-classes.
data EClass l = EClass
    { forall (l :: * -> *). EClass l -> ClassId
eClassId      :: {-# UNPACK #-} !ClassId -- ^ E-class identifier
    , forall (l :: * -> *). EClass l -> Set (ENode l)
eClassNodes   :: !(S.Set (ENode l))      -- ^ E-nodes in this class
    , forall (l :: * -> *). EClass l -> Domain l
eClassData    :: Domain l                -- ^ The analysis data associated with this eclass.
    , forall (l :: * -> *). EClass l -> SList (ClassId, ENode l)
eClassParents :: !(SList (ClassId, ENode l))   -- ^ E-nodes which are parents of this e-class and their corresponding e-class ids.
    }

instance (Show (Domain l), Show1 l) => Show (EClass l) where
    show :: EClass l -> String
show (EClass ClassId
a Set (ENode l)
b Domain l
d (SList [(ClassId, ENode l)]
c ClassId
_)) = String
"Id: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show ClassId
a forall a. Semigroup a => a -> a -> a
<> String
"\nNodes: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Set (ENode l)
b forall a. Semigroup a => a -> a -> a
<> String
"\nParents: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show [(ClassId, ENode l)]
c forall a. Semigroup a => a -> a -> a
<> String
"\nData: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Domain l
d