smaoin 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+71/−25 lines, 4 filesdep ~basedep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, bytestring
API changes (from Hackage documentation)
- Data.Smaoin: RealNum :: Integer -> Integer -> RealNum
+ Data.Smaoin: expo :: RealNum -> Integer
+ Data.Smaoin: instance Eq Entity
+ Data.Smaoin: instance Eq Number
+ Data.Smaoin: instance Eq Statement
+ Data.Smaoin: instance Eq Value
+ Data.Smaoin: instance Show Entity
+ Data.Smaoin: instance Show Number
+ Data.Smaoin: instance Show ObjectSection
+ Data.Smaoin: instance Show PredicateSection
+ Data.Smaoin: instance Show Statement
+ Data.Smaoin: instance Show StatementBlock
+ Data.Smaoin: instance Show Value
+ Data.Smaoin: realnum :: Integer -> Integer -> RealNum
+ Data.Smaoin: res :: String -> Resource
+ Data.Smaoin: sig :: RealNum -> Integer
Files
- NEWS +26/−0
- smaoin.cabal +3/−3
- src/Data/Smaoin.hs +37/−17
- test/test.hs +5/−5
NEWS view
@@ -3,6 +3,32 @@ +smaoin 0.3.0.0 -- 2015-06-18+============================++General, build and documentation changes:++* (None)++New APIs, features and enhancements:++* Add shortcut function `res` for `Resource` construction+* Hide `RealNum` data constructor behind a normalizing function, and add+ getters for the `RealNum` fields+* Add Eq and Show instances to several types++Bug fixes:++* (None)++Dependency changes:++* (None)+++++ smaoin 0.2.0.0 -- 2015-06-01 ============================
smaoin.cabal view
@@ -1,5 +1,5 @@ name: smaoin-version: 0.2.0.0+version: 0.3.0.0 synopsis: Utilities for the Smaoin semantic information model. description: This package provides basic types and functions for working with the Smaoin model in Haskell. But these are@@ -43,7 +43,7 @@ type: exitcode-stdio-1.0 hs-source-dirs: test main-is: test.hs- build-depends: base >=4.7 && <5- , bytestring >=0.10+ build-depends: base+ , bytestring , QuickCheck >=2.8 , smaoin
src/Data/Smaoin.hs view
@@ -15,7 +15,11 @@ module Data.Smaoin ( Resource (..)- , RealNum (..)+ , res+ , RealNum ()+ , sig+ , expo+ , realnum , Rational (..) , Number (..) , Value (..)@@ -30,7 +34,9 @@ import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BL+import Data.Maybe (fromMaybe) import Data.Ratio+import Data.String (fromString) import qualified Data.Text.Lazy as T import qualified Data.UUID as U import qualified System.Random as R@@ -44,7 +50,7 @@ instance R.Random Resource where randomR (Resource a, Resource b) g = (Resource $ U.toASCIIBytes u, h) where- f r = maybe U.nil id (U.fromASCIIBytes r)+ f r = fromMaybe U.nil (U.fromASCIIBytes r) (u, h) = R.randomR (f a, f b) g random g = (Resource $ U.toASCIIBytes u, h)@@ -52,17 +58,34 @@ u :: U.UUID (u, h) = R.random g --- | Arbitrary precision real number. The first argument is the significand,--- and the second is an exponent. @RealNum s e@ represents the number--- @s * 10^e@. This representation allows to precisely encode any real number--- expressed in Idan (excluding rational numbers expressed as fractions).+-- | Shortcut for creating a 'Resource' from a 'String'. The string is simply+-- converted into a byte sequence.+res :: String -> Resource+res = Resource . fromString++-- | Arbitrary precision real number. -- -- While @RealNum@ is an instance of @Num@, the implementation isn't intended -- for general math use, and is probably much simpler than what the scientific -- Haskell packages provide. However, it is certainly suitable for basic -- manipulations.-data RealNum = RealNum Integer Integer deriving Show+data RealNum = RealNum Integer Integer deriving (Eq, Show) +-- | Get the significand of a 'RealNum', i.e. the /s/ in /s * 10^e/+sig :: RealNum -> Integer+sig (RealNum s _) = s++-- | Get the exponent of a 'RealNum', i.e. the /e/ in /s * 10^e/+expo :: RealNum -> Integer+expo (RealNum _ e) = e++-- | Create a 'RealNum'. The first argument is the significand, and the second+-- is an exponent. @realnum s e@ represents the number @s * 10^e@. This+-- representation allows to precisely encode any real number expressed in Idan+-- (excluding rational numbers expressed as ratios).+realnum :: Integer -> Integer -> RealNum+realnum s e = normalize $ RealNum s e+ radix :: Integer radix = 10 @@ -77,11 +100,6 @@ then cleanZeros d (y + 1) else (x, y) -instance Eq RealNum where- m == n = normalize m `e` normalize n- where- (RealNum s1 e1) `e` (RealNum s2 e2) = s1 == s2 && e1 == e2- instance Num RealNum where (RealNum s1 e1) + (RealNum s2 e2) = normalize $ RealNum (s1' + s2') e' where@@ -100,7 +118,7 @@ negate (RealNum s e) = RealNum (negate s) e -- | A Smaoin number can be represented as a real number or as a ratio.-data Number = RealNumber RealNum | RatioNumber Rational+data Number = RealNumber RealNum | RatioNumber Rational deriving (Eq, Show) -- | A Smaoin value, i.e. an entity with predefined meaning and traits. The -- type can be specified statically through a dedicated data constructor, or@@ -111,16 +129,18 @@ | String T.Text | Chunk BL.ByteString | Generic T.Text Resource+ deriving (Eq, Show) -- | A Smaoin entity. It is the atomic concept in Smaoin: Everything is an -- entity. An entity can be described (resource) or predefined (value).-data Entity = ResourceE Resource | ValueE Value+data Entity = ResourceE Resource | ValueE Value deriving (Eq, Show) -- | Statements can be grouped in lists and containers to form simple -- in-memory datastores, query results and so on. -- -- Parameters are: Identifier, subject, predicate, object. data Statement = Statement Resource Resource Resource Entity+ deriving (Eq, Show) -- An object section is attached to subjects and predicated to form -- statements. It contains the object of a statement, and the identifier that@@ -128,7 +148,7 @@ -- predicate. -- -- Parameters are: Object, identifier.-data ObjectSection = ObjectSection Entity Resource+data ObjectSection = ObjectSection Entity Resource deriving Show -- | A predicate section is meant to be attached to a subject. It describes it -- through one or more statements. It expresses predicate-object-identifier@@ -136,7 +156,7 @@ -- own set of object-identifier pairs. -- -- Parameters: Predicate; Objects and identifiers.-data PredicateSection = PredicateSection Resource [ObjectSection]+data PredicateSection = PredicateSection Resource [ObjectSection] deriving Show -- | A statement block describes a single subject, by expressing one or more -- statements which share that subject. The predicate sections contain the@@ -145,7 +165,7 @@ -- simple in-memory datastores, query results and so on. -- -- Parameters: 1) Subject; 2) Predicates, objects, identifiers.-data StatementBlock = StatementBlock Resource [PredicateSection]+data StatementBlock = StatementBlock Resource [PredicateSection] deriving Show -- | Create a fresh new Uid. It is randomly generated, using the global random -- generator. 'Resource' is a 'R.Random' instance, so you can use any other
test/test.hs view
@@ -27,10 +27,10 @@ unless (all isSuccess results) exitFailure prop_plus :: Bool-prop_plus = (RealNum 5 3) + (RealNum 2 4) == (RealNum 25 3)+prop_plus = realnum 5 3 + realnum 2 4 == realnum 25 3 prop_mult :: Bool-prop_mult = (RealNum 5 3) * (RealNum 2 4) == (RealNum 1 8)+prop_mult = realnum 5 3 * realnum 2 4 == realnum 1 8 prop_generateUid :: IO Bool prop_generateUid = do@@ -40,7 +40,7 @@ tests :: [(String, IO Result)] tests =- [ ("(+)", quickCheckResult prop_plus)- , ("(*)", quickCheckResult prop_mult)- , ("generateUid", prop_generateUid >>= quickCheckResult)+ [ ("(+)", quickCheckResult prop_plus)+ , ("(*)", quickCheckResult prop_mult)+ , ("generateUid", quickCheckResult =<< prop_generateUid) ]