summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2018-02-23 18:18:05 +0300
committerdefanor <defanor@uberspace.net>2018-02-23 18:18:05 +0300
commitc249c4d8a8e6dbc4c95f656973126ab5ec07df49 (patch)
tree4ba0a6bf7c7548f856c59809672552ffefde9963
parentcf2776fc2ce561cffc85bf9e6a11289372ea7fbb (diff)
downloadredland-c249c4d8a8e6dbc4c95f656973126ab5ec07df49.zip
redland-c249c4d8a8e6dbc4c95f656973126ab5ec07df49.tar.gz
redland-c249c4d8a8e6dbc4c95f656973126ab5ec07df49.tar.bz2
Add NFData instances for Node and Triple
-rw-r--r--Redland/Util.hs44
-rw-r--r--redland.cabal1
2 files changed, 29 insertions, 16 deletions
diff --git a/Redland/Util.hs b/Redland/Util.hs
index 962bf2e..600cc83 100644
--- a/Redland/Util.hs
+++ b/Redland/Util.hs
@@ -12,6 +12,7 @@ module Redland.Util where
import Foreign
import Control.Monad
+import Control.DeepSeq
import Redland.LowLevel
import Redland.MidLevel
@@ -51,12 +52,21 @@ data LiteralNodeType = XMLSchema String
| LanguageTag String
deriving (Ord, Eq, Show)
+instance NFData LiteralNodeType where
+ rnf (XMLSchema s) = rnf s
+ rnf (LanguageTag s) = rnf s
+
-- | Haskell representation of 'RedlandNode'.
data Node = BlankNode String
| LiteralNode String (Maybe LiteralNodeType)
| ResourceNode String
deriving (Ord, Eq, Show)
+instance NFData Node where
+ rnf (BlankNode s) = rnf s
+ rnf (LiteralNode s t) = rnf s `seq` rnf t
+ rnf (ResourceNode s) = rnf s
+
-- | A conversion function.
redlandNodeToNode :: ForeignPtr RedlandNode -> IO Node
redlandNodeToNode rn = do
@@ -69,7 +79,6 @@ redlandNodeToNode rn = do
litVal <- nodeGetLiteralValue rn
litLang <- nodeGetLiteralValueLanguage rn
litType <- nodeGetLiteralValueDatatypeURI rn
- litXML <- nodeGetLiteralValueIsWellFormedXML rn
let nType = case (litLang, litType) of
(Just l, _) -> Just $ LanguageTag l
(_, Just t) -> Just $ XMLSchema t
@@ -159,6 +168,9 @@ data Triple = Triple { subject :: Maybe Node
, object :: Maybe Node
} deriving (Ord, Eq, Show)
+instance NFData Triple where
+ rnf (Triple s p o) = rnf s `seq` rnf p `seq` rnf o
+
-- | A conversion function.
statementToTriple :: ForeignPtr RedlandStatement
-> IO Triple
@@ -211,21 +223,21 @@ streamToList stream = do
-- | Initializes world, storage, model, and base URI at once.
withWSMU :: String
- -- ^ storage factory
- -> [(String, String)]
- -- ^ storage options
- -> String
- -- ^ storage identifier
- -> String
- -- ^ model options
- -> String
- -- ^ base URI
- -> (ForeignPtr RedlandWorld ->
- ForeignPtr RedlandStorage ->
- ForeignPtr RedlandModel ->
- ForeignPtr RedlandURI ->
- IO a)
- -> IO a
+ -- ^ storage factory
+ -> [(String, String)]
+ -- ^ storage options
+ -> String
+ -- ^ storage identifier
+ -> String
+ -- ^ model options
+ -> String
+ -- ^ base URI
+ -> (ForeignPtr RedlandWorld ->
+ ForeignPtr RedlandStorage ->
+ ForeignPtr RedlandModel ->
+ ForeignPtr RedlandURI ->
+ IO a)
+ -> IO a
withWSMU sFactory sOpt sIdent mOpt bURI f =
withNew redlandWorld $ \world ->
withHash world "memory" sOpt $ \sOpt' ->
diff --git a/redland.cabal b/redland.cabal
index 2f2b314..6191541 100644
--- a/redland.cabal
+++ b/redland.cabal
@@ -28,6 +28,7 @@ library
, Redland.Util
other-extensions: ForeignFunctionInterface
build-depends: base >=4.9 && <5
+ , deepseq >= 1.4.2.0
default-language: Haskell2010
pkgconfig-depends: raptor2, redland
build-tools: hsc2hs