Commits

Doug Burke  committed dfed73a

Added IsString instances for QName/ScopedName; marked Swish.Utils.DateTime as deprecated

  • Participants
  • Parent commits 32dd5fe

Comments (0)

Files changed (8)

     - added toRDFTriple and fromRDFTriple functions that take advantage
       of the To/FromRDFLabel typeclasses to ease conversion from/to Arcs.
 
+  - QName and ScopedName:
+
+    - added IsString instance
+
   - UTCTime support (To/FromRDFLabel) has required adding old-locale
     and time to the package constraints.
 
 
   - added Swish and Swish.RDF modules for documentation purposes.
 
+  - marked Swish.Utils.DateTime as deprecated.
+
 0.3.0.3:
 
   - to be written

File Swish/Utils/DateTime.hs

 --  Portability :  H98
 --
 --  This Module defines a collection of date/time manipulation functions. It
---  should probably be replaced by standard modules from Hackage. 
+--  is deprecated - since it's functionality is available from other
+--  modules - and will be removed in a future release.
+--
+--------------------------------------------------------------------------------
 --
 --  Date/time value manipulation.
 --
 --      defined by RFC 3339.
 --      Timezone interpretation is per RFC3339.
 --
---------------------------------------------------------------------------------
 --
 --            year,month,day,hour,min,sec,millisec,timezone
 --class (Show a,Eq a) => DateTimeClass a where

File Swish/Utils/Namespace.hs

     )
 where
 
-import Swish.Utils.QName
-    ( QName(..), getQNameURI )
+import Swish.Utils.QName (QName(..), getQNameURI)
+import Swish.Utils.LookupMap (LookupEntryClass(..))
 
-import Swish.Utils.LookupMap
-    ( LookupEntryClass(..) )
+import Data.String (IsString(..))
 
 ------------------------------------------------------------
 --  Namespace, having a prefix and a URI
 getScopeURI :: ScopedName -> String
 getScopeURI = nsURI . snScope
 
+instance IsString ScopedName where
+  fromString = makeUriScopedName
+    
 instance Eq ScopedName where
     (==) = snEq
 
             pre = nsPrefix n
             uri = nsURI n
 
---  Scoped names are equal of ther corresponding QNames are equal
+--  Scoped names are equal if their corresponding QNames are equal
 snEq :: ScopedName -> ScopedName -> Bool
 snEq s1 s2 = getQName s1 == getQName s2
 

File Swish/Utils/PartOrderedCollection.hs

 --
 --  This module provides methods to support operations on partially ordered
 --  collections.  The partial ordering relationship is represented by
---  Maybe `Ordering`.
+--  `Maybe Ordering`.
 --
 --  Thanks to members of the haskell-cafe mailing list -
---    Robert (rvollmert-lists@gmx.net) and
---    Tom Pledger (Tom.Pledger@peace.com) -
+--    Robert (rvollmert-lists\@gmx.net) and
+--    Tom Pledger (Tom.Pledger\@peace.com) -
 --  who suggested key ideas on which some of the code in this module is based.
 --
 --------------------------------------------------------------------------------

File Swish/Utils/QName.hs

 
 import System.Directory (canonicalizePath)
 import System.FilePath (splitDirectories)
+import Data.String (IsString(..))
 import Data.List (intercalate)
 
 ------------------------------------------------------------
 
 data QName = QName { qnNsuri, qnLocal :: String }
 
+instance IsString QName where
+  fromString = qnameFromURI
+
+instance Eq QName where
+    (==) = qnEq
+
+instance Ord QName where
+    (QName u1 l1) <= (QName u2 l2) =
+        if up1 /= up2 then up1 <= up2 else (ur1++l1) <= (ur2++l2)
+        where
+            n   = min (length u1) (length u2)
+            (up1,ur1) = splitAt n u1
+            (up2,ur2) = splitAt n u2
+
+instance Show QName where
+    show (QName ns ln) = "<" ++ ns ++ ln ++ ">"
+
 newQName :: String -> String -> QName
 newQName = QName
 
 getQNameURI :: QName -> String
 getQNameURI (QName ns ln) = ns++ln
 
-instance Eq QName where
-    (==) = qnEq
-
-instance Ord QName where
-    (QName u1 l1) <= (QName u2 l2) =
-        if up1 /= up2 then up1 <= up2 else (ur1++l1) <= (ur2++l2)
-        where
-            n   = min (length u1) (length u2)
-            (up1,ur1) = splitAt n u1
-            (up2,ur2) = splitAt n u2
-
-instance Show QName where
-    show (QName ns ln) = "<" ++ ns ++ ln ++ ">"
-
 --  Original used comparison of concatenated strings,
 --  but that was very inefficient.  This version does the
 --  comparison without constructing new values
   `Swish.RDF.RDFGraph.FromRDFLabel` classes and the 
   `Swish.RDF.RDFGraph.toRDFTriple` and `Swish.RDF.RDFGraph.fromRDFTriple`
   functions.
-  Added instances: @IsString RDFLabel@ and @Monoid NSGraph@.
+  Added instances: @IsString RDFLabel@, @IsString QName@, @IsString ScopedName@
+  and @Monoid NSGraph@.
   The modules "Swish" and "Swish.RDF" have been introduced to provide
-  documentation.
+  documentation. The module "Swish.Utils.DateTime" is deprecated and
+  will be removed in a later release.
   .
   [Version 0.3.0.3] Changed @scripts/SwishExample.ss@ script so that the
   proof succeeds. Some documentation improvements, including a discussion

File tests/QNameTest.hs

+{-# LANGUAGE OverloadedStrings #-}
+
 --------------------------------------------------------------------------------
 --  See end of this file for licence information.
 --------------------------------------------------------------------------------
 qu1, qu2, qu3, qu4, qu5 :: QName
 qu1 = qnameFromURI "http://id.ninebynine.org/wip/2003/test/graph1/node#s1"
 qu2 = qnameFromURI "http://id.ninebynine.org/wip/2003/test/graph2/node/s2"
-qu3 = qnameFromURI "http://id.ninebynine.org/wip/2003/test/graph3/node"
-qu4 = qnameFromURI "http://id.ninebynine.org/wip/2003/test/graph5/"
-qu5 = qnameFromURI "http://id.ninebynine.org/wip/2003/test/graph5/s5"
+qu3 = "http://id.ninebynine.org/wip/2003/test/graph3/node"
+qu4 = "http://id.ninebynine.org/wip/2003/test/graph5/"
+qu5 = "http://id.ninebynine.org/wip/2003/test/graph5/s5"
 
 testMakeQNameSuite :: Test
 testMakeQNameSuite = 

File tests/RDFGraphTest.hs

 
 import Swish.Utils.ListHelpers (equiv)
 
-import Swish.RDF.GraphClass
-    ( Label(..), arc )
+import Swish.RDF.GraphClass (Label(..), arc)
 
 import Swish.Utils.Namespace
     ( Namespace(..)
     , ScopedName(..)
     , nullScopedName
-    , makeUriScopedName
     )
 
 import Swish.RDF.RDFGraph
 --  Construct version of g1 using just URIs
 
 uris1, urip1, urio1 :: ScopedName
-uris1 = makeUriScopedName "http://id.ninebynine.org/wip/2003/test/graph1/node#s1"
-urip1 = makeUriScopedName "http://id.ninebynine.org/wip/2003/test/graph1/node#p1"
-urio1 = makeUriScopedName "http://id.ninebynine.org/wip/2003/test/graph1/node#o1"
+uris1 = "http://id.ninebynine.org/wip/2003/test/graph1/node#s1"
+urip1 = "http://id.ninebynine.org/wip/2003/test/graph1/node#p1"
+urio1 = "http://id.ninebynine.org/wip/2003/test/graph1/node#o1"
 
 tu01 :: RDFTriple
 tu01  = toRDFTriple uris1 urip1 urio1