packages feed

NearContextAlgebra-0.1.0.0: src/NearContext.hs

{-# 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 (Transportation(..),TransportationContext(..), 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 Transportation =
 -- | 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 TransportationContext = Context Transportation

-- | to provide the model with the function universe we make an instance of Enumerable from the Algebra.Enumerable module
instance Enumerable Transportation 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 TransportationContext where

 -- | returns all TransportationContexts
 --
 -- >>>  universe ::[TransportationContext]
 -- [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::[Transportation])

-- | the context type forms a lattice with a upper bound that can be retrieved by the function top
instance BoundedMeetSemiLattice TransportationContext where

 -- | returns the contexts active in the upper contexts, what means no context is active, synonym for one in my thesis
 --
 -- >>> top ::TransportationContext
 -- One [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]]
 top = One (universe::[Context Transportation])