[Fencommits] fenfire-hs: provide toRDFList and readRDFList which take a function for writing/reading the elements of the list to/from RDF
Benja Fallenstein
benja.fallenstein at gmail.com
Fri Mar 23 12:26:32 EET 2007
Fri Mar 23 12:25:41 EET 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* provide toRDFList and readRDFList which take a function for writing/reading the elements of the list to/from RDF
diff -rN -u old-fenfire-hs/Fenfire/RDF.hs new-fenfire-hs/Fenfire/RDF.hs
--- old-fenfire-hs/Fenfire/RDF.hs 2007-03-23 12:26:31.000000000 +0200
+++ new-fenfire-hs/Fenfire/RDF.hs 2007-03-23 12:26:31.000000000 +0200
@@ -280,22 +280,26 @@
toRDF :: a -> ToRdfM Node
instance FromRDF a => FromRDF [a] where
- readRDF g l | l == rdf_nil = return []
- | otherwise = do
+ readRDF g l = readRDFList readRDF g l
+
+readRDFList f g l | l == rdf_nil = return []
+ | otherwise = do
first <- mquery (l, rdf_first, X) g
rest <- mquery (l, rdf_next, X) g
tellTs [ (l, rdf_first, first), (l, rdf_next, rest) ]
- x <- readRDF g first
- xs <- readRDF g rest
+ x <- f g first
+ xs <- readRDFList f g rest
return (x:xs)
instance ToRDF a => ToRDF [a] where
- toRDF [] = return rdf_nil
- toRDF (x:xs) = do l <- newBNode; first <- toRDF x; next <- toRDF xs
- tellTs [ (l, rdf_first, first)
- , (l, rdf_next, next) ]
- return l
-
+ toRDF = toRDFList toRDF
+
+toRDFList _ [] = return rdf_nil
+toRDFList f (x:xs) = do l <- newBNode; first <- f x; next <- toRDFList f xs
+ tellTs [ (l, rdf_first, first)
+ , (l, rdf_next, next) ]
+ return l
+
instance FromRDF String where
fromRDF _ (Literal s _) = s
fromRDF _ n = error $ "Fenfire.RDF.fromRDF(String): can only convert literals, not " ++ show n
More information about the Fencommits
mailing list