{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-| Module : NearContext Description : declares all data types to represent the contexts used in the near example Maintainer : hahn@geoinfo.tuwien.ac.at Stability : beta Models the contexts of the concept near -} module NearContext (NearContext(..),NearContextLattice(..), universe, top, arbitrary) where import ContextLattice import Algebra.Enumerable import Algebra.Lattice import qualified Data.List as L import Test.QuickCheck -- * the context type used to model the concept near -- | this data type represents all contexts that are used in the near model, make sure to derive all the type classes data NearContext = -- | constructor represents the context walking Walking -- | constructor represents the context driving | Driving -- | constructor for the context uphill | Uphill deriving (Show,Eq,Ord,Enum,Bounded) -- | type synonym type NearContextLattice = Context NearContext -- | to provide the model with the function universe we make an instance of Enumerable from the Algebra.Enumerable module instance Enumerable NearContext where -- | returns all contexts, needs the type classes Bounded and Enum to work -- -- >>> universe ::[Transportation] -- [Walking,Driving,Uphill] universe = universeBounded -- | also the wrapped type has to be an instance of Enumerable instance Enumerable NearContextLattice where -- | returns all NearContexts -- -- >>> universe ::[NearContextLattice] -- [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]] universe = tail. L.map Ctx . L.subsequences $ (universe::[NearContext]) -- | the context type forms a lattice with a upper bound that can be retrieved by the function top instance BoundedMeetSemiLattice NearContextLattice where -- | returns the contexts active in the upper contexts, what means no context is active, synonym for one in my thesis -- -- >>> top ::NearContextLattice -- One [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]] top = One (universe::[Context NearContext])