smaoin 0.1.1.2 → 0.2.0.0
raw patch · 5 files changed
+90/−24 lines, 5 filesdep +randomdep +uuiddep ~basedep ~bytestringdep ~textPVP ok
version bump matches the API change (PVP)
Dependencies added: random, uuid
Dependency ranges changed: base, bytestring, text
API changes (from Hackage documentation)
- Data.Smaoin: Value :: Value -> Entity
- Data.Smaoin: type Resource = ByteString
+ Data.Smaoin: ResourceE :: Resource -> Entity
+ Data.Smaoin: ValueE :: Value -> Entity
+ Data.Smaoin: generateUid :: IO Resource
+ Data.Smaoin: instance Eq Resource
+ Data.Smaoin: instance Random Resource
+ Data.Smaoin: instance Show Resource
+ Data.Smaoin: newtype Resource
- Data.Smaoin: Resource :: Resource -> Entity
+ Data.Smaoin: Resource :: ByteString -> Resource
Files
- NEWS +32/−0
- README +1/−5
- smaoin.cabal +10/−7
- src/Data/Smaoin.hs +31/−9
- test/test.hs +16/−3
NEWS view
@@ -1,3 +1,35 @@+This file lists the user-visible interesting changes between releases. For a+full list of changes to the source, see the ChangeLog.++++smaoin 0.2.0.0 -- 2015-06-01+============================++General, build and documentation changes:++* Some compatibility breaking name changes and `Resource` became a newtype+* The link in the package description works now+* Documentation comments were added++New APIs, features and enhancements:++* New unique `Resource`s can be generated. It is an instance of `Random`, and+ there is a shortcut function `generateUid` which uses the global random+ generator.++Bug fixes:++* (None)++Dependency changes:++* Dependency versions now have no upper bounds+++++ smaoin 0.1.1.2 -- 2015-05-06 ============================
README view
@@ -1,15 +1,11 @@-This is a small Haskell library for tagging plain text and token streams with-positions - line, column and character numbers. These are useful for locating-lexer errors, debugging and more.- See the .cabal file for more info and link to project website the version control. The official download locations are: +- Hackage - The project website - Torrents-- Hackage This library is free software, and is committed to software freedom. It is released to the public domain using the CC0 Public Domain Dedication. For the
smaoin.cabal view
@@ -1,5 +1,5 @@ name: smaoin-version: 0.1.1.2+version: 0.2.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@@ -7,9 +7,9 @@ application level functions are/will be provided in other packages. .- More info about Smaoin:+ More info about the Smaoin model: .- http://rel4tion.org/projects/smaoin/+ <http://rel4tion.org/projects/smaoin/> homepage: http://rel4tion.org/projects/smaoin-hs/ bug-reports: http://rel4tion.org/projects/smaoin-hs/tickets/ license: PublicDomain@@ -30,9 +30,11 @@ exposed-modules: Data.Smaoin --other-modules: -- other-extensions: - build-depends: base ==4.7.*- , bytestring ==0.10.*- , text ==1.2.*+ build-depends: base >=4.7 && <5+ , bytestring >=0.10+ , random >=1.1+ , text >=1.2+ , uuid >=1.3 hs-source-dirs: src default-language: Haskell2010 @@ -41,6 +43,7 @@ type: exitcode-stdio-1.0 hs-source-dirs: test main-is: test.hs- build-depends: base ==4.7.*+ build-depends: base >=4.7 && <5+ , bytestring >=0.10 , QuickCheck >=2.8 , smaoin
src/Data/Smaoin.hs view
@@ -14,7 +14,7 @@ -} module Data.Smaoin- ( Resource+ ( Resource (..) , RealNum (..) , Rational (..) , Number (..)@@ -24,6 +24,7 @@ , ObjectSection (..) , PredicateSection (..) , StatementBlock (..)+ , generateUid ) where @@ -31,16 +32,26 @@ import qualified Data.ByteString.Lazy as BL import Data.Ratio import qualified Data.Text.Lazy as T+import qualified Data.UUID as U+import qualified System.Random as R -{--PLAN:-- set-based model (can work as list, ordered set and unordered set)-- tree-based model-- maybe graph-based model?--}+-- | A Smaoin resource identifier, also known as a Uid.+--+-- A resource in Smaoin is some idea or object in the broad sense, which can be+-- described using statements, and be related to other resources.+newtype Resource = Resource BS.ByteString deriving (Eq, Show) -type Resource = BS.ByteString+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)+ (u, h) = R.randomR (f a, f b) g + random g = (Resource $ U.toASCIIBytes u, h)+ where+ 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@@ -91,6 +102,9 @@ -- | A Smaoin number can be represented as a real number or as a ratio. data Number = RealNumber RealNum | RatioNumber Rational +-- | A Smaoin value, i.e. an entity with predefined meaning and traits. The+-- type can be specified statically through a dedicated data constructor, or+-- generically as a resource. data Value = Boolean Bool | Number Number | Character Char@@ -98,7 +112,9 @@ | Chunk BL.ByteString | Generic T.Text Resource -data Entity = Resource Resource | Value Value+-- | 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 -- | Statements can be grouped in lists and containers to form simple -- in-memory datastores, query results and so on.@@ -130,3 +146,9 @@ -- -- Parameters: 1) Subject; 2) Predicates, objects, identifiers. data StatementBlock = StatementBlock Resource [PredicateSection]++-- | 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+-- random generator.+generateUid :: IO Resource+generateUid = R.randomIO
test/test.hs view
@@ -14,6 +14,8 @@ -} import Control.Monad (unless)+import qualified Data.ByteString as BS+import Data.Smaoin import System.Exit import Test.QuickCheck import Test.QuickCheck.Test@@ -24,10 +26,21 @@ results <- mapM (\ (name ,action) -> printf "%-25s: " name >> action) tests unless (all isSuccess results) exitFailure -prop_todo :: Bool-prop_todo = True+prop_plus :: Bool+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_generateUid :: IO Bool+prop_generateUid = do+ (Resource r1) <- generateUid+ (Resource r2) <- generateUid+ return $ BS.length r1 == BS.length r2+ tests :: [(String, IO Result)] tests =- [ ("todo", quickCheckResult prop_todo)+ [ ("(+)", quickCheckResult prop_plus)+ , ("(*)", quickCheckResult prop_mult)+ , ("generateUid", prop_generateUid >>= quickCheckResult) ]