-- GSoC 2015 - Haskell bindings for OpenCog. {-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} -- | This Module defines some useful data types for proper interaction -- with the AtomSpace C wrapper library. -- Intended for internal use only. module OpenCog.AtomSpace.Internal ( Handle(..) , HandleSeq(..) , TVRaw(..) , fromTVRaw , toTVRaw , TVTypeEnum(..) , tvMAX_PARAMS ) where import Foreign (Ptr) import Data.Functor ((<$>)) import Data.Typeable (cast,Typeable) import OpenCog.AtomSpace.Sugar (noTv) import OpenCog.AtomSpace.Types (AtomName(..),AtomType(..) ,Atom(..),TruthVal(..)) type Handle = Ptr () type HandleSeq = Ptr Handle -- Constant with the maximum number of parameters in any type of TV. tvMAX_PARAMS :: Int tvMAX_PARAMS = 5 -- TV enum type to work with TruthValueTypes from -- definition. -- Note: this data type must be always similar to the definition on ../TruthValue.h. -- The order of enum types MUST be exactly the same on both sites. data TVTypeEnum = NULL_TRUTH_VALUE | SIMPLE_TRUTH_VALUE | COUNT_TRUTH_VALUE | INDEFINITE_TRUTH_VALUE | FUZZY_TRUTH_VALUE | PROBABILISTIC_TRUTH_VALUE deriving (Enum,Eq,Show) data TVRaw = TVRaw TVTypeEnum [Double] deriving (Eq,Show) toTVRaw :: TruthVal -> TVRaw toTVRaw (SimpleTV a b ) = TVRaw SIMPLE_TRUTH_VALUE [a,b] toTVRaw (CountTV a b c ) = TVRaw COUNT_TRUTH_VALUE [a,b,c] toTVRaw (IndefTV a b c d e) = TVRaw INDEFINITE_TRUTH_VALUE [a,b,c,d,e] toTVRaw (FuzzyTV a b ) = TVRaw FUZZY_TRUTH_VALUE [a,b] toTVRaw (ProbTV a b c ) = TVRaw PROBABILISTIC_TRUTH_VALUE [a,b,c] fromTVRaw :: TVRaw -> TruthVal fromTVRaw (TVRaw SIMPLE_TRUTH_VALUE (a:b:_)) = SimpleTV a b fromTVRaw (TVRaw COUNT_TRUTH_VALUE (a:b:c:_)) = CountTV a b c fromTVRaw (TVRaw INDEFINITE_TRUTH_VALUE (a:b:c:d:e:_)) = IndefTV a b c d e fromTVRaw (TVRaw FUZZY_TRUTH_VALUE (a:b:_)) = FuzzyTV a b fromTVRaw (TVRaw PROBABILISTIC_TRUTH_VALUE (a:b:c:_)) = ProbTV a b c