1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 22:31:36 +03:00
semantic/src/Category.hs

30 lines
938 B
Haskell
Raw Normal View History

{-# LANGUAGE FlexibleInstances #-}
module Category where
2015-11-18 22:23:35 +03:00
2015-11-27 20:02:15 +03:00
import Term
import Control.Comonad.Cofree
2015-11-18 22:23:35 +03:00
import Data.Set
2016-02-05 00:35:42 +03:00
-- | A standardized category of AST node. Used to determine the semantics for
-- | semantic diffing and define comparability of nodes.
data Category =
-- | A literal key-value data structure.
DictionaryLiteral
-- | A non-standard category, which can be used for comparability.
| Other String
2016-02-05 00:43:05 +03:00
deriving (Eq, Show)
2016-02-05 00:35:42 +03:00
-- | The class of types that have categories.
2015-11-18 22:23:35 +03:00
class Categorizable a where
categories :: a -> Set String
2015-11-27 20:02:15 +03:00
instance Categorizable annotation => Categorizable (Term a annotation) where
categories (annotation :< _) = categories annotation
-- | Test whether the categories from the categorizables intersect.
comparable :: Categorizable a => a -> a -> Bool
comparable a b = catsA == catsB || (not . Data.Set.null $ intersection catsA catsB)
where
catsA = categories a
catsB = categories b