Commits

Doug Burke committed 3275871

RDFLabel now has Lit/LangLit/TypedLit rather than just Lit

Comments (0)

Files changed (20)

 0.7.0.0:
 
+  - RDF literals are now stored using the Lit, LangLit, or TypedLit
+    constructors (from RDFLabel) rather than using just Lit.
+
+  - Removed mkTypedLit from Swish.RDF.RDFParser; use
+    Swish.RDF.RDFDatatype.makeDataTypedLiteral instead.
+
   - Removed asubj, apred and aobj from Swish.RDF.GraphClass and
     Swish.RDF.RDFGraph; use arcSubj, arcPred or arcObj instead.
     
 - Should there be a type-level constaint that an RDF Arc can only have
   a literal in the object position?
 
-- the RDFLabel data type could be split up to add additional type
-  constraints, namely Lit could be split up into something like ULit
-  for an untyped literal, LLit for a language lit coupled with a
-  LString type that combines text and language tag), and DLit for a
-  literal with a datatype. This would require a minor version update
-
-  An alternative change would be to make it 'Lit RDFLiteral' with
-  RDFLiteral having the Untyped/Typed/Language options.
+- Change LangLit to have a language-code datatype rather than use
+  a ScopedName.
 
 - can items be moved out of Swidh.RDF.RDFGraph (e.g. the RDFlabel
   re-exports)?

src/Swish/RDF/N3Formatter.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  N3Formatter
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
   )
 
 import Swish.RDF.Vocabulary (
-  isLang, langTag, 
+  langTag, 
   rdfType,
   rdfNil,
   owlSameAs, logImplies
 -- does not match the syntax used in N3, so we need to convert here.     
 -- Rather than converting back to a Double and then displaying that       
 -- we just convert E to e for now.      
---      
-formatLabel _ (Lit lit (Just dtype)) 
-  | dtype == xsdDouble = return $ B.fromText $ T.toLower lit
-  | dtype `elem` [xsdBoolean, xsdDecimal, xsdInteger] = return $ B.fromText lit
-  | otherwise = return $ quoteText lit `mappend` formatAnnotation dtype
-formatLabel _ (Lit lit Nothing) = return $ quoteText lit
+--
+formatLabel _ (TypedLit lit dtype)
+    | dtype == xsdDouble = return $ B.fromText $ T.toLower lit
+    | dtype `elem` [xsdBoolean, xsdDecimal, xsdInteger] = return $ B.fromText lit
+    | otherwise = return $ quoteText lit `mappend` "^^" `mappend` showScopedName dtype
+formatLabel _ (LangLit lit lcode) =
+    return $ quoteText lit `mappend` "@" `mappend` B.fromText (langTag lcode)
+formatLabel _ (Lit lit) = return $ quoteText lit
 
 formatLabel _ lab = return $ B.fromString $ show lab
 
--- the annotation for a literal (ie type or language)
-formatAnnotation :: ScopedName -> B.Builder
-formatAnnotation a  | isLang a  = "@" `mappend` B.fromText (langTag a)
-                    | otherwise = "^^" `mappend` showScopedName a
-
 {-
 We have to decide whether to use " or """ to quote
 the string.
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/N3Parser.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  N3Parser
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
     , xsdBoolean, xsdInteger, xsdDecimal, xsdDouble
     )
 
+import Swish.RDF.RDFDatatype (makeDatatypedLiteral)
+
 import Swish.RDF.RDFParser
     ( SpecialMap
     , ParseResult
     , symbol
     , lexeme
     , whiteSpace
-    , mkTypedLit
     , hex4  
     , hex8  
     , appendURIs
 type AddStatement = RDFLabel -> N3Parser ()
 
 addStatement :: RDFLabel -> RDFLabel -> AddStatement
-addStatement s p o@(Lit _ (Just dtype)) | dtype `elem` [xsdBoolean, xsdInteger, xsdDecimal, xsdDouble] = do 
+addStatement s p o@(TypedLit _ dtype) | dtype `elem` [xsdBoolean, xsdInteger, xsdDecimal, xsdDouble] = do 
   ost <- stGet
   let stmt = arc s p o
       oldp = prefixUris ost
 -}
 
 boolean :: N3Parser RDFLabel
-boolean = mkTypedLit xsdBoolean <$> 
+boolean = makeDatatypedLiteral xsdBoolean <$> 
           (atWord "false" <|> atWord "true")
           -- (try (atWord "false") <|> atWord "true")
            
 -}
 
 literal :: N3Parser RDFLabel
-literal = Lit <$> n3string <*> optional dtlang
+literal = do
+    lit <- n3string
+    opt <- optional dtlang
+    return $ case opt of
+               Just (Left lcode)  -> LangLit lit lcode
+               Just (Right dtype) -> TypedLit lit dtype
+               _                  -> Lit lit
   
-dtlang :: N3Parser ScopedName
+dtlang :: N3Parser (Either ScopedName ScopedName)
 dtlang = 
-  (char '@' *> langcode)
-  <|> string "^^" *> n3symbol
-  -- <|> (try (string "^^") *> n3symbol)
+  (char '@' *> (Left <$> langcode))
+  <|> string "^^" *> (Right <$> n3symbol)
 
 langcode :: N3Parser ScopedName
 langcode = do
 
 numericLiteral :: N3Parser RDFLabel
 numericLiteral =
-  -- -- try (mkTypedLit xsdDouble <$> n3double)
+  -- -- try (makeDatatypedLiteral xsdDouble <$> n3double)
   -- try (d2s <$> n3double)
-  -- <|> try (mkTypedLit xsdDecimal <$> n3decimal)
+  -- <|> try (makeDatatypedLiteral xsdDecimal <$> n3decimal)
   d2s <$> n3double
-  <|> mkTypedLit xsdDecimal . T.pack <$> n3decimal
-  <|> mkTypedLit xsdInteger . T.pack <$> n3integer
+  <|> makeDatatypedLiteral xsdDecimal . T.pack <$> n3decimal
+  <|> makeDatatypedLiteral xsdInteger . T.pack <$> n3integer
 
 n3sign :: N3Parser Char
 n3sign = char '+' <|> char '-'
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/NTFormatter.hs

     ( Arc(..) )
 
 import Swish.Utils.Namespace (ScopedName, getQName)
-import Swish.RDF.Vocabulary (isLang, langTag)
+import Swish.RDF.Vocabulary (langTag)
 
 import Swish.Utils.LookupMap
     ( LookupMap, emptyLookupMap
 formatLabel :: RDFLabel -> Formatter B.Builder
 formatLabel lab@(Blank _) = mapBlankNode lab
 formatLabel (Res sn) = return $ showScopedName sn
-formatLabel (Lit lit Nothing) = return $ quoteText lit
-formatLabel (Lit lit (Just nam)) | isLang nam = return $ mconcat [quoteText lit, at, B.fromText (langTag nam)]
-                                 | otherwise  = return $ mconcat [quoteText lit, carets, showScopedName nam]
+formatLabel (Lit lit) = return $ quoteText lit
+formatLabel (LangLit lit lang) = return $ mconcat [quoteText lit, at, B.fromText (langTag lang)]
+formatLabel (TypedLit lit dt)  = return $ mconcat [quoteText lit, carets, showScopedName dt]
 
 -- do not expect to get the following, but include
 -- just in case rather than failing

src/Swish/RDF/NTParser.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  NTParser
---  Copyright   :  (c) 2011 Douglas Burke
+--  Copyright   :  (c) 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 -}
 
 literal :: NTParser RDFLabel
-literal = Lit <$> (T.pack <$> ntstring) <*> optional dtlang
+literal = do
+    lit <- T.pack <$> ntstring
+    opt <- optional dtlang
+    return $ case opt of
+               Just (Left lcode)  -> LangLit lit lcode
+               Just (Right dtype) -> TypedLit lit dtype
+               _                  -> Lit lit
 
 ntstring :: NTParser String
 ntstring = bracket (char '"') (char '"') (many character)
 
-dtlang :: NTParser ScopedName
+dtlang :: NTParser (Either ScopedName ScopedName)
 dtlang = 
-    (char '@' *> language)
-    <|> (string "^^" *> uriref)
+    (char '@' *> (Left <$> language))
+    <|> (string "^^" *> (Right <$> uriref))
 
 language :: NTParser ScopedName
 language = do
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/RDFDatatype.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFDatatype
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
         dtnam = tvalName dtv
         dtmap = tvalMap dtv
 
--- | Create a typed literal from the given value.
-makeDatatypedLiteral :: ScopedName -> T.Text -> RDFLabel
-makeDatatypedLiteral dtnam txtval =
-    Lit txtval (Just dtnam)
+-- | Create a typed literal. No conversion is made to the
+-- string representation.
+makeDatatypedLiteral :: 
+    ScopedName   -- ^ data type
+    -> T.Text    -- ^ string form of the value
+    -> RDFLabel
+makeDatatypedLiteral = flip TypedLit
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/RDFDatatypeXsdString.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFDatatypeXsdString
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
         }
     where
         app1 vbind = app2 (vbMap vbind svar) (vbMap vbind lvar) vbind
-        app2 (Just (Lit s (Just _)))
-             (Just (Lit l Nothing))
+
+        -- Going to assume can only get TypedLit here, and assume LangLit
+        -- can be ignored.
+        app2 (Just (TypedLit s _))
+             (Just (Lit l))
              vbind
              | s == l
              = [vbind]
-        app2 (Just (Lit s (Just _)))
+        app2 (Just (TypedLit s _))
              Nothing
              vbind
-             = [addVarBinding lvar (Lit s Nothing) vbind]
+             = [addVarBinding lvar (Lit s) vbind]
         app2 Nothing
-             (Just (Lit l Nothing))
+             (Just (Lit l))
              vbind
-             = [addVarBinding svar (Lit l (Just typeNameXsdString)) vbind]
+             = [addVarBinding svar (TypedLit l typeNameXsdString) vbind]
         app2 _ _ _ = []
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/RDFGraph.hs

 import Data.Monoid (Monoid(..))
 import Data.Maybe (mapMaybe)
 import Data.Char (ord, isDigit)
+import Data.Function (on)
 import Data.Hashable (hashWithSalt)
 import Data.List (intersect, union, findIndices, foldl')
 import Data.Ord (comparing)
 --  (c) a \"NoNode\" option is defined.
 --      This might otherwise be handled by @Maybe (RDFLabel g)@.
 --
+-- Prior to version @0.7.0.0@, literals were represented by a
+-- single constructor, @Lit@, with an optional argument.
+--
 data RDFLabel =
       Res ScopedName                    -- ^ resource
-    | Lit T.Text (Maybe ScopedName)     -- ^ literal [type/language]
+    | Lit T.Text                        -- ^ a plain literal
+    | LangLit T.Text ScopedName         -- ^ a literal with an associated language
+    | TypedLit T.Text ScopedName        -- ^ a literal with an associated data type
     | Blank String                      -- ^ blank node
     | Var String                        -- ^ variable (not used in ordinary graphs)
     | NoNode                            -- ^ no node  (not used in ordinary graphs)
 
--- TODO: should Lit be split up so that can easily differentiate between
--- a type and a language tag?
+-- TODO: LangLit should use a language encoding type rather than a scoped name.
+
+langCompare :: ScopedName -> ScopedName -> Bool
+langCompare = (==) `on` (T.toLower . langTag)
 
 -- | Define equality of nodes possibly based on different graph types.
 --
     Blank b1 == Blank b2 = b1 == b2
     Var v1   == Var v2   = v1 == v2
 
-    Lit s1 Nothing   == Lit s2 Nothing   = s1 == s2
-    Lit s1 (Just t1) == Lit s2 (Just t2) = s1 == s2 && (t1 == t2 ||
-                                                        (isLang t1 && isLang t2 &&
-                                                         (T.toLower . langTag) t1 == (T.toLower . langTag) t2))
-    
+    Lit s1         == Lit s2         = s1 == s2
+    LangLit s1 t1  == LangLit s2 t2  = s1 == s2 && langCompare t1 t2
+    TypedLit s1 t1 == TypedLit s2 t2 = s1 == s2 && t1 == t2
+
     _  == _ = False
 
 instance Show RDFLabel where
     show (Res sn)           = show sn
-    show (Lit st Nothing)   = quote1Str st
+    show (Lit st)           = quote1Str st
+    show (LangLit st lang)  = quote1Str st ++ "@"  ++ T.unpack (langTag lang)
+    show (TypedLit st dtype) 
+        | dtype `elem` [xsdBoolean, xsdDouble, xsdDecimal, xsdInteger] = T.unpack st
+        | otherwise  = quote1Str st ++ "^^" ++ show dtype
+
+    {-
     show (Lit st (Just nam))
         | isLang nam = quote1Str st ++ "@"  ++ T.unpack (langTag nam)
         | nam `elem` [xsdBoolean, xsdDouble, xsdDecimal, xsdInteger] = T.unpack st
         | otherwise  = quote1Str st ++ "^^" ++ show nam
+    -}
+
     show (Blank ln)         = "_:"++ln
     show (Var ln)           = '?' : ln
     show NoNode             = "<NoNode>"
     compare (Blank ln1)    (Blank ln2)    = compare ln1 ln2
     compare (Res _)        (Blank _)      = LT
     compare (Blank _)      (Res _)        = GT
+
+    compare (Lit s1)       (Lit s2)       = compare s1 s2
+
     -- .. else use show string comparison
     compare l1 l2 = comparing show l1 l2
     
     labelIsVar (Blank _)    = True
     labelIsVar (Var _)      = True
     labelIsVar _            = False
+
     getLocal   (Blank loc)  = loc
     getLocal   (Var   loc)  = '?':loc
     getLocal   (Res   sn)   = "Res_" ++ T.unpack (getScopeLocal sn)
     getLocal   (NoNode)     = "None"
     getLocal   _            = "Lit_"
+
     makeLabel  ('?':loc)    = Var loc
     makeLabel  loc          = Blank loc
+
     labelHash seed lb       = hashWithSalt seed (showCanon lb)
 
 instance IsString RDFLabel where
-  fromString = flip Lit Nothing . T.pack
+  fromString = Lit . T.pack
 
 {-|
 A type that can be converted to a RDF Label.
     _ -> Nothing
     
 fLabel :: (T.Text -> Maybe a) -> ScopedName -> RDFLabel -> Maybe a
-fLabel conv dtype (Lit xs (Just dt)) | dt == dtype = conv xs
-                                     | otherwise   = Nothing
+fLabel conv dtype (TypedLit xs dt) | dt == dtype = conv xs
+                                   | otherwise   = Nothing
 fLabel _    _     _ = Nothing
   
 tLabel :: (Show a) => ScopedName -> (String -> T.Text) -> a -> RDFLabel                      
-tLabel dtype conv = flip Lit (Just dtype) . conv . show                      
+tLabel dtype conv = flip TypedLit dtype . conv . show                      
 
 -- | The character is converted to an untyped literal of length one.
 instance ToRDFLabel Char where
-  toRDFLabel = flip Lit Nothing . T.singleton
+  toRDFLabel = Lit . T.singleton
 
 -- | The label must be an untyped literal containing a single character.
 instance FromRDFLabel Char where
-  fromRDFLabel (Lit cs Nothing) | T.compareLength cs 1 == EQ = Just (T.head cs)
-                                | otherwise = Nothing
+  fromRDFLabel (Lit cs) | T.compareLength cs 1 == EQ = Just (T.head cs)
+                        | otherwise = Nothing
   fromRDFLabel _ = Nothing
 
 -- | Strings are converted to untyped literals.
 instance ToRDFLabel String where
-  toRDFLabel = flip Lit Nothing . T.pack
+  toRDFLabel = Lit . T.pack
 
 -- | Only untyped literals are converted to strings.
 instance FromRDFLabel String where
-  fromRDFLabel (Lit xs Nothing) = Just (T.unpack xs)
-  fromRDFLabel _ = Nothing
+  fromRDFLabel (Lit xs) = Just (T.unpack xs)
+  fromRDFLabel _        = Nothing
 
 textToBool :: T.Text -> Maybe Bool
 textToBool s | s `elem` ["1", "true"]  = Just True
 
 -- | Converts to a literal with a @xsd:boolean@ datatype.
 instance ToRDFLabel Bool where
-  toRDFLabel b = Lit (if b then "true" else "false") (Just xsdBoolean)
+  toRDFLabel b = TypedLit (if b then "true" else "false") xsdBoolean
                                                  
 -- | Converts from a literal with a @xsd:boolean@ datatype. The
 -- literal can be any of the supported XSD forms - e.g. \"0\" or
                       | otherwise    = toL $ T.pack $ printf "%E" f
                         
                         where
-                          toL = flip Lit (Just dtype)
+                          toL = flip TypedLit dtype
 
 -- textToRealFloat :: (RealFloat a) => (a -> Maybe a) -> T.Text -> Maybe a
 textToRealFloat :: (RealFloat a, Read a) => (a -> Maybe a) -> T.Text -> Maybe a
     
 -- | Converts to a literal with a @xsd:datetime@ datatype.
 instance ToRDFLabel UTCTime where
-  toRDFLabel = flip Lit (Just xsdDateTime) . T.pack . fromUTCFormat
+  toRDFLabel = flip TypedLit xsdDateTime . T.pack . fromUTCFormat
   
 -- | Converts from a literal with a @xsd:datetime@ datatype.
 instance FromRDFLabel UTCTime where
   
 -- | Converts to a literal with a @xsd:date@ datatype.
 instance ToRDFLabel Day where
-  toRDFLabel = flip Lit (Just xsdDate) . T.pack . fromDayFormat
+  toRDFLabel = flip TypedLit xsdDate . T.pack . fromDayFormat
 
 -- | Converts from a literal with a @xsd:date@ datatype.
 instance FromRDFLabel Day where
 --
 --  This is used for hashing, so that equivalent labels always return
 --  the same hash value.
---    
+--
+--  TODO: can remove the use of quote1Str as all we care about is
+--  a unique output, not that it is valid in any RDF format. Also
+--  rename to showForHash or something like that, since it is only used
+--  for this purpose.
+--
 showCanon :: RDFLabel -> String
 showCanon (Res sn)           = "<"++show (getScopedNameURI sn)++">"
-showCanon (Lit st (Just nam))
-        | isLang nam = quote1Str st ++ "@"  ++ T.unpack (langTag nam)
-        | otherwise  = quote1Str st ++ "^^" ++ show (getScopedNameURI nam)
+showCanon (Lit st)           = show st
+showCanon (LangLit st lang)  = quote1Str st ++ "@"  ++ T.unpack (langTag lang)
+showCanon (TypedLit st dt)   = quote1Str st ++ "^^" ++ show (getScopedNameURI dt)
 showCanon s                  = show s
 
 -- | See `quote`.
 isUri  _      = False
 
 -- |Test if supplied labal is a literal node
+-- ('Lit', 'LangLit', or 'TypedLit').
 isLiteral :: RDFLabel -> Bool
-isLiteral (Lit _ _) = True
-isLiteral  _        = False
+isLiteral (Lit _)        = True
+isLiteral (LangLit _ _)  = True
+isLiteral (TypedLit _ _) = True
+isLiteral  _             = False
 
--- |Test if supplied labal is an untyped literal node
+-- |Test if supplied labal is an untyped literal node (either
+-- 'Lit' or 'LangLit').
 isUntypedLiteral :: RDFLabel -> Bool
-isUntypedLiteral (Lit _ Nothing  ) = True
-isUntypedLiteral (Lit _ (Just tn)) = isLang tn
-isUntypedLiteral  _                = False
+isUntypedLiteral (Lit _)       = True
+isUntypedLiteral (LangLit _ _) = True
+isUntypedLiteral  _            = False
 
--- |Test if supplied labal is an untyped literal node
+-- |Test if supplied labal is a typed literal node ('TypedLit').
 isTypedLiteral :: RDFLabel -> Bool
-isTypedLiteral (Lit _ (Just tn)) = not (isLang tn)
-isTypedLiteral  _                = False
+isTypedLiteral (TypedLit _ _) = True
+isTypedLiteral  _             = False
 
--- |Test if supplied labal is an XML literal node
+-- |Test if supplied labal is a XML literal node
 isXMLLiteral :: RDFLabel -> Bool
 isXMLLiteral = isDatatyped rdfXMLLiteral
 
--- |Test if supplied label is an typed literal node of a given datatype
+-- |Test if supplied label is a typed literal node of a given datatype
 isDatatyped :: ScopedName -> RDFLabel -> Bool
-isDatatyped d  (Lit _ (Just n)) = n == d
-isDatatyped _  _                = False
+isDatatyped d  (TypedLit _ dt) = d == dt
+isDatatyped _  _               = False
 
 -- |Test if supplied label is a container membership property
 --
 isQueryVar (Var _) = True
 isQueryVar  _      = False
 
--- |Extract text value from a literal node
+-- |Extract text value from a literal node (including the
+-- Language and Typed variants). The empty string is returned
+-- for other nodes.
 getLiteralText :: RDFLabel -> T.Text
-getLiteralText (Lit s _) = s
-getLiteralText  _        = ""
+getLiteralText (Lit s)        = s
+getLiteralText (LangLit s _)  = s
+getLiteralText (TypedLit s _) = s
+getLiteralText  _             = ""
 
--- |Extract ScopedName value from a resource node
+-- |Extract the ScopedName value from a resource node ('nullScopedName'
+-- is returned for non-resource nodes).
 getScopedName :: RDFLabel -> ScopedName
 getScopedName (Res sn) = sn
 getScopedName  _       = nullScopedName
   let lbls = concatMap arcLabels arcs
       
       getNS (Res s) = Just s
-      getNS (Lit _ (Just tn)) | not (isLang tn) = Just tn
-                              | otherwise = Nothing
+      getNS (TypedLit _ dt) = Just dt
       getNS _ = Nothing
 
       ns = mapMaybe (fmap getScopeNamespace . getNS) lbls

src/Swish/RDF/RDFParser.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFParser
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
     , noneOf
     , eoln
     , fullStop
-    , mkTypedLit
     , hex4
     , hex8
     , appendURIs
     )
     where
 
-import Swish.RDF.RDFGraph (RDFGraph, RDFLabel(..))
+import Swish.RDF.RDFGraph (RDFGraph)
 import Swish.RDF.Vocabulary
     ( namespaceRDF
     , namespaceRDFS
 
 -}
 
--- | Create a typed literal.
-mkTypedLit ::
-  ScopedName -- ^ the type
-  -> T.Text  -- ^ the value
-  -> RDFLabel
-mkTypedLit u v = Lit v (Just u)
-
 {-
 Handle hex encoding; the spec for N3 and NTriples suggest that
 only upper-case A..F are valid but you can find lower-case values
         
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/RDFProofContext.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFProofContext
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
     , rdfVarBindingMemberProp
     )
 
-import Swish.RDF.RDFGraph
-    ( RDFLabel(..)
-    , isUri, isDatatyped
-    , getLiteralText )
+import Swish.RDF.RDFGraph (RDFLabel(..), isUri)
 
 import Swish.RDF.VarBinding
     ( applyVarBinding
     , scopeRDFD
     )
 
-import Control.Monad (liftM)
 import Data.Monoid (Monoid(..))
-import Data.Maybe (isJust, fromJust)
 
 import qualified Data.Text as T
 import qualified Data.Text.Lazy.Builder as B
             else
                 []
 
+{-
 getCanonical :: RDFLabel -> RDFLabel -> RDFLabel -> Maybe RDFLabel
 getCanonical v1 t1 t2 =
     if isDatatyped dqn1 v1 && isJust mdt1 then
 
         getRes (Res dqnam) = dqnam
         getRes x = error $ "Expected a Resource, sent " ++ show x -- for -Wall
+-}
+
+getCanonical :: RDFLabel -> RDFLabel -> RDFLabel -> Maybe RDFLabel
+getCanonical (TypedLit v dt) (Res dqn1) (Res dqn2) =
+    if dt == dqn1
+    then case findRDFDatatype dqn1 of
+           Just dt1 -> flip TypedLit dqn2 `fmap` typeMkCanonicalForm dt1 v
+           _ -> Nothing
+
+    else Nothing
+
+getCanonical _                _          _  = Nothing
+
+
 
 {- -- Test data
 qnamint = ScopedName namespaceXSD "integer"
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke  
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke  
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/TurtleFormatter.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  TurtleFormatter
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
   )
 
 import Swish.RDF.Vocabulary (
-  isLang
-  , langTag 
+  langTag 
   , rdfType
   , rdfNil
   , xsdBoolean, xsdDecimal, xsdInteger, xsdDouble 
 -- Rather than converting back to a Double and then displaying that       
 -- we just convert E to e for now.      
 --      
-formatLabel _ (Lit lit (Just dtype)) 
-  | dtype == xsdDouble = return $ B.fromText $ T.toLower lit
-  | dtype `elem` [xsdBoolean, xsdDecimal, xsdInteger] = return $ B.fromText lit
-  | otherwise = return $ quoteText lit `mappend` formatAnnotation dtype
-formatLabel _ (Lit lit Nothing) = return $ quoteText lit
+formatLabel _ (Lit lit) = return $ quoteText lit
+formatLabel _ (LangLit lit lcode) = return $ quoteText lit `mappend` "@" `mappend` B.fromText (langTag lcode)
+formatLabel _ (TypedLit lit dtype)
+    | dtype == xsdDouble = return $ B.fromText $ T.toLower lit
+    | dtype `elem` [xsdBoolean, xsdDecimal, xsdInteger] = return $ B.fromText lit
+    | otherwise = return $ quoteText lit `mappend` "^^" `mappend` showScopedName dtype
 
 formatLabel _ lab = return $ B.fromString $ show lab
 
--- the annotation for a literal (ie type or language)
-formatAnnotation :: ScopedName -> B.Builder
-formatAnnotation a  | isLang a  = "@" `mappend` B.fromText (langTag a)
-                    | otherwise = "^^" `mappend` showScopedName a
-
 {-|
 Convert text into a format for display in Turtle. The idea
 is to use one double quote unless three are needed, and to
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

src/Swish/RDF/TurtleParser.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  TurtleParser
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
     , defaultBase
     )
 
+import Swish.RDF.RDFDatatype (makeDatatypedLiteral)
+
 import Swish.RDF.RDFParser
     ( ParseResult
     , runParserWithError
     , isymbol
     , lexeme
     , whiteSpace
-    , mkTypedLit
     , hex4  
     , hex8  
     , appendURIs
 -}
 
 addStatement :: RDFLabel -> RDFLabel -> RDFLabel -> TurtleParser ()
-addStatement s p o@(Lit _ (Just dtype)) | dtype `elem` [xsdBoolean, xsdInteger, xsdDecimal, xsdDouble] = do 
+addStatement s p o@(TypedLit _ dtype) | dtype `elem` [xsdBoolean, xsdInteger, xsdDecimal, xsdDouble] = do 
   ost <- stGet
   let stmt = arc s p o
       oldp = prefixUris ost
 
 rdfLiteral :: TurtleParser RDFLabel
 rdfLiteral = do
-  lbl <- turtleString
-  opt <- optional (_langTag <|> (string "^^" *> iriref))
-  return $ Lit (L.toStrict lbl) opt
+  lbl <- L.toStrict <$> turtleString
+  opt <- optional ((Left <$> _langTag) <|> (string "^^" *> (Right <$> iriref)))
+  return $ case opt of
+             Just (Left lcode)  -> LangLit lbl lcode
+             Just (Right dtype) -> TypedLit lbl dtype
+             _                  -> Lit lbl
 
 {-
 [61s] NumericLiteral ::= NumericLiteralUnsigned 
 numericLiteralUnsigned = 
   d2s <$> _double
   <|> 
-  (mkTypedLit xsdDecimal . L.toStrict <$> _decimal)
+  (makeDatatypedLiteral xsdDecimal . L.toStrict <$> _decimal)
   <|> 
-  (mkTypedLit xsdInteger . L.toStrict <$> _integer)
+  (makeDatatypedLiteral xsdInteger . L.toStrict <$> _integer)
 
 {-
 [63s] NumericLiteralPositive ::= INTEGER_POSITIVE 
 numericLiteralPositive =
   d2s <$> _doublePositive
   <|> 
-  (mkTypedLit xsdDecimal . L.toStrict <$> _decimalPositive)
+  (makeDatatypedLiteral xsdDecimal . L.toStrict <$> _decimalPositive)
   <|> 
-  (mkTypedLit xsdInteger . L.toStrict <$> _integerPositive)
+  (makeDatatypedLiteral xsdInteger . L.toStrict <$> _integerPositive)
 
 {-
 [64s] NumericLiteralNegative ::= INTEGER_NEGATIVE 
 numericLiteralNegative = 
   d2s <$> _doubleNegative
   <|> 
-  (mkTypedLit xsdDecimal . L.toStrict <$> _decimalNegative)
+  (makeDatatypedLiteral xsdDecimal . L.toStrict <$> _decimalNegative)
   <|> 
-  (mkTypedLit xsdInteger . L.toStrict <$> _integerNegative)
+  (makeDatatypedLiteral xsdInteger . L.toStrict <$> _integerNegative)
    
 {-
 [65s] BooleanLiteral ::= "true" 
 -}
 
 booleanLiteral :: TurtleParser RDFLabel
-booleanLiteral = mkTypedLit xsdBoolean . T.pack <$> (string "true" <|> string "false")
+booleanLiteral = makeDatatypedLiteral xsdBoolean . T.pack <$> (string "true" <|> string "false")
 
 {-
 [66s] String ::= STRING_LITERAL1 
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.
   .
   Changes in version @0.7.0.0@:
   .
+  * RDF literals are now stored using the @Lit@, @LangLit@, or @TypedLit@ constructors
+  (@RDFLabel@) rather than using just @Lit@.
+  .
+  * Removed @mkTypedLit@ from @Swish.RDF.RDFParser@; use
+  @Swish.RDF.RDFDatatype.makeDataTypedLiteral@ instead.
+  .
   * Removed @asubj@, @apred@ and @aobj@ from @Swish.RDF.GraphClass@ and
   @Swish.RDF.RDFGraph@; use @arcSubj@, @arcPred@ or @arcObj@ instead.
   .

tests/N3FormatterTest.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  N3FormatterTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 l14txt = "lx14"
 
 toL :: B.Builder -> RDFLabel
-toL = flip Lit Nothing . L.toStrict . B.toLazyText
+toL = Lit . L.toStrict . B.toLazyText
 
 l1, l2, l3, l11, l12, l13, l14 :: RDFLabel
 l1  = toL l1txt
 l14 = toL l14txt
 
 lfr, lfoobar :: RDFLabel
-lfr = Lit "chat et chien" (Just (langName "fr"))
-lfoobar = Lit "foo bar" (Just (makeNSScopedName base1 "o1"))
+lfr = LangLit "chat et chien" (langName "fr")
+lfoobar = TypedLit "foo bar" (makeNSScopedName base1 "o1")
   
 f1, f2 :: RDFLabel
 f1 = Res $ makeNSScopedName base1 "f1"
   in toRDFGraph arcs
    
 graph_l4 = toGraph [ toRDFTriple s1 p1 ("A string with \"quotes\"" :: RDFLabel)
-                   , toRDFTriple s2 p2 (Lit "A typed string with \"quotes\"" (Just (fromString "urn:a#b")))
+                   , toRDFTriple s2 p2 (TypedLit "A typed string with \"quotes\"" (fromString "urn:a#b"))
                    ]                    
                     
 ------------------------------------------------------------
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

tests/N3ParserTest.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  N3ParserTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 oa = Res $ makeNSScopedName basea "c"
 
 l1, l2, l3 :: RDFLabel
-l1 = Lit "l1"  Nothing
-l2 = Lit "l2-'\"line1\"'\n\nl2-'\"\"line2\"\"'" Nothing
-l3 = Lit "l3--\r\"'\\--\x0020\&--\x00A0\&--" Nothing
+l1 = Lit "l1"
+l2 = Lit "l2-'\"line1\"'\n\nl2-'\"\"line2\"\"'"
+l3 = Lit "l3--\r\"'\\--\x0020\&--\x00A0\&--"
 
 lfr, lxml, lfrxml :: RDFLabel
-lfr    = Lit "chat"          $ Just $ langName "fr"
-lxml   = Lit "<br/>"         $ Just rdfXMLLiteral
-lfrxml = Lit "<em>chat</em>" $ Just rdfXMLLiteral
+lfr    = LangLit "chat"           $ langName "fr"
+lxml   = TypedLit "<br/>"         rdfXMLLiteral
+lfrxml = TypedLit "<em>chat</em>" rdfXMLLiteral
 
 bTrue, bFalse :: RDFLabel
-bTrue  = Lit "true"  $ Just xsdBoolean
-bFalse = Lit "false" $ Just xsdBoolean
+bTrue  = TypedLit "true"  xsdBoolean
+bFalse = TypedLit "false" xsdBoolean
 
 f1, f2 :: RDFLabel
 f1 = Res $ makeNSScopedName base1 "f1"
 lit_g2 = lit_g1 { namespaces = xnslist }
 
 bOne, b20, b221, b23e4 :: RDFLabel
-bOne  = Lit "1" $ Just xsdInteger
-b20   = Lit "2.0" $ Just xsdDecimal
-b221  = Lit "-2.21" $ Just xsdDecimal
-b23e4 = Lit "-2.3E-4" $ Just xsdDouble
+bOne  = TypedLit "1"       xsdInteger
+b20   = TypedLit "2.0"     xsdDecimal
+b221  = TypedLit "-2.21"   xsdDecimal
+b23e4 = TypedLit "-2.3E-4" xsdDouble
 
 lit_g4 :: RDFGraph
 lit_g4 = mempty {
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.
 --------------------------------------------------------------------------------
 -- |
 --  Module      :  NTTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 -}
 
 l0, l1, l2, l3, l4 :: RDFLabel
-l0 = Lit "" Nothing
-l1 = Lit "l1"  Nothing
-l2 = Lit "l2-'\"line1\"'\n\nl2-'\"\"line2\"\"'" Nothing
-l3 = Lit "l3--\r\"'\\--\x20&--\x17A&--" Nothing
-l4 = Lit "l4 \\" Nothing
+l0 = Lit ""
+l1 = Lit "l1"
+l2 = Lit "l2-'\"line1\"'\n\nl2-'\"\"line2\"\"'"
+l3 = Lit "l3--\r\"'\\--\x20&--\x17A&--"
+l4 = Lit "l4 \\"
 
 lfr, lgben, lxml1, lxml2 :: RDFLabel
-lfr    = Lit "chat"          (Just $ langName "fr")
-lgben  = Lit "football"      (Just $ langName "en-gb")
-lxml1  = Lit "<br/>"         (Just rdfXMLLiteral)
-lxml2  = Lit "<em>chat</em>" (Just rdfXMLLiteral)
+lfr    = LangLit "chat"           $ langName "fr"
+lgben  = LangLit "football"       $ langName "en-gb"
+lxml1  = TypedLit "<br/>"         rdfXMLLiteral
+lxml2  = TypedLit "<em>chat</em>" rdfXMLLiteral
 
 b1 , b2 :: RDFLabel
 b1 = Blank "x1"
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

tests/RDFDatatypeXsdIntegerTest.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFDatatypeXsdIntegerTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 rdfVB (v,b) = (Var v,Blank b)                   -- (Variable,Blank)
 
 rdfVL :: (String, String) -> (RDFLabel, RDFLabel)
-rdfVL (v,l) = (Var v,Lit (T.pack l) Nothing)             -- (Variable,Untyped literal)
+rdfVL (v,l) = (Var v, Lit (T.pack l))             -- (Variable,Untyped literal)
 
 rdfVI :: (String, String) -> (RDFLabel, RDFLabel)
-rdfVI (v,l) = (Var v,Lit (T.pack l) (Just typeNameXsdInteger))
+rdfVI (v,l) = (Var v, TypedLit (T.pack l) typeNameXsdInteger)
                                                 -- (Variable,Integer literal)
 
 makeBVR :: [(String,ScopedName)] -> RDFVarBinding
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke
 --  All rights reserved.
 --
 --  This file is part of Swish.

tests/RDFGraphTest.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFGraphTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 l1, l2, l2gb, l3, l4, l5, l6, l7, l8,
   l9, l10, l11, l12 :: RDFLabel
 l1   = "l1" -- use IsString instance
-l2   = Lit "l2"  (Just (langName "en")) 
-l2gb = Lit "l2"  (Just (langName "en-gb")) 
-l3   = Lit "l2"  (Just (langName "fr")) 
-l4   = Lit "l4"  (Just qb1t1)           
-l5   = Lit "l4"  (Just qb1t1)           
-l6   = Lit "l4"  (Just qb1t1)           
-l7   = Lit "l4"  (Just qb1t2)           
-l8   = Lit "l4"  (Just qb1t2)           
-l9   = Lit "l4"  (Just qb1t2)           
-l10  = Lit "l10" (Just rdfXMLLiteral)  
--- l11  = Lit "l11" (Just rdfXMLLiteral)  
--- l12  = Lit "l12" (Just rdfXMLLiteral)  
-l11  = Lit "l10" (Just rdfXMLLiteral)   -- are these meant to both be l10?
-l12  = Lit "l10" (Just rdfXMLLiteral)   -- if you change them some tests fail
+l2   = LangLit "l2"  (langName "en")
+l2gb = LangLit "l2"  (langName "en-gb")
+l3   = LangLit "l2"  (langName "fr")
+l4   = TypedLit "l4"  qb1t1    
+l5   = TypedLit "l4"  qb1t1           
+l6   = TypedLit "l4"  qb1t1           
+l7   = TypedLit "l4"  qb1t2           
+l8   = TypedLit "l4"  qb1t2           
+l9   = TypedLit "l4"  qb1t2           
+l10  = TypedLit "l10" rdfXMLLiteral
+-- l11  = TypedLit "l11" (Just rdfXMLLiteral)  
+-- l12  = TypedLit "l12" (Just rdfXMLLiteral)  
+l11  = TypedLit "l10"  rdfXMLLiteral   -- are these meant to both be l10?
+l12  = TypedLit "l10"  rdfXMLLiteral   -- if you change them some tests fail
 
 nanF, infF, ninfF :: RDFLabel
-nanF  = Lit "NaN" (Just xsdFloat)
-infF  = Lit "INF" (Just xsdFloat)
-ninfF = Lit "-INF" (Just xsdFloat)
+nanF  = TypedLit "NaN"  xsdFloat
+infF  = TypedLit "INF"  xsdFloat
+ninfF = TypedLit "-INF" xsdFloat
 
 nanD, infD, ninfD :: RDFLabel
-nanD  = Lit "NaN" (Just xsdDouble)
-infD  = Lit "INF" (Just xsdDouble)
-ninfD = Lit "-INF" (Just xsdDouble)
+nanD  = TypedLit "NaN"  xsdDouble
+infD  = TypedLit "INF"  xsdDouble
+ninfD = TypedLit "-INF" xsdDouble
 
 v1, v2, v3, v4, vb3, vb4 :: RDFLabel
 v1  = Var "v1"  
 
 -- test ToRDFLabel/FromRDFlabel/IsString instances
 --
+
+toLbl :: T.Text -> Maybe ScopedName -> RDFLabel
+toLbl sVal (Just dtype) = TypedLit sVal dtype
+toLbl sVal _            = Lit sVal
     
 testToConv :: 
   (ToRDFLabel a, Eq a, Show a) 
   => String -> T.Text -> Maybe ScopedName -> a -> Test
 testToConv lbl sVal dtype hVal = 
-  let rdfVal = Lit sVal dtype
-  in testEq (":tconv:" ++ lbl) rdfVal (toRDFLabel hVal)
+    testEq (":tconv:" ++ lbl) (toLbl sVal dtype) $ toRDFLabel hVal
   
 testFrConv :: 
   (FromRDFLabel a, Eq a, Show a) 
   => String -> T.Text -> Maybe ScopedName -> a -> Test
 testFrConv lbl sVal dtype hVal = 
-  let rdfVal = Lit sVal dtype
-  in testEq (":fconv:" ++ lbl) (Just hVal)  (fromRDFLabel rdfVal)
+    testEq (":fconv:" ++ lbl) (Just hVal) $ fromRDFLabel (toLbl sVal dtype)
   
 testConv :: 
   (ToRDFLabel a, FromRDFLabel a, Eq a, Show a) 
     -- failure case
     testEq "fconv:fail chr1"    (Nothing :: Maybe Char)   (fromRDFLabel l1)
   , testEq "fconv:fail chr2"    (Nothing :: Maybe Char)   (fromRDFLabel s1)
-  , testEq "fconv:fail str1"    (Nothing :: Maybe String) (fromRDFLabel (Lit "1.23" (Just xsdFloat)))
+  , testEq "fconv:fail str1"    (Nothing :: Maybe String) (fromRDFLabel (TypedLit "1.23" xsdFloat))
   , testEq "fconv:fail bool1"   (Nothing :: Maybe Bool)  (fromRDFLabel l1)
-  , testEq "fconv:fail bool2"   (Nothing :: Maybe Bool)  (fromRDFLabel (Lit "True" (Just xsdBoolean))) -- should we just let this be valid?
-  , testEq "fconv:fail bool3"   (Nothing :: Maybe Bool)  (fromRDFLabel (Lit "true" (Just xsdFloat)))
+  , testEq "fconv:fail bool2"   (Nothing :: Maybe Bool)  (fromRDFLabel (TypedLit "True" xsdBoolean)) -- should we just let this be valid?
+  , testEq "fconv:fail bool3"   (Nothing :: Maybe Bool)  (fromRDFLabel (TypedLit "true" xsdFloat))
   , testEq "fconv:fail int1"    (Nothing :: Maybe Int)  (fromRDFLabel l1)
-  , testEq "fconv:fail int2"    (Nothing :: Maybe Int)  (fromRDFLabel (Lit "123456789012345" (Just xsdInteger))) 
+  , testEq "fconv:fail int2"    (Nothing :: Maybe Int)  (fromRDFLabel (TypedLit "123456789012345" xsdInteger)) 
   , testEq "fconv:fail float1"  (Nothing :: Maybe Float)  (fromRDFLabel l1)
-  , testEq "fconv:fail float2"  (Nothing :: Maybe Float)  (fromRDFLabel (Lit "1.234e101" (Just xsdFloat))) -- invalid input 
-  , testEq "fconv:fail float3"  (Nothing :: Maybe Float)  (fromRDFLabel (Lit "-1.234e101" (Just xsdFloat))) -- invalid input 
-  , testEq "fconv:fail float4"  (Nothing :: Maybe Float)  (fromRDFLabel (Lit "NaNs" (Just xsdFloat))) -- invalid input 
-  , testEq "fconv:fail dbl1"    (Nothing :: Maybe Double)  (fromRDFLabel (Lit "1.23" (Just xsdFloat))) -- invalid input 
+  , testEq "fconv:fail float2"  (Nothing :: Maybe Float)  (fromRDFLabel (TypedLit "1.234e101" xsdFloat)) -- invalid input 
+  , testEq "fconv:fail float3"  (Nothing :: Maybe Float)  (fromRDFLabel (TypedLit "-1.234e101" xsdFloat)) -- invalid input 
+  , testEq "fconv:fail float4"  (Nothing :: Maybe Float)  (fromRDFLabel (TypedLit "NaNs" xsdFloat)) -- invalid input 
+  , testEq "fconv:fail dbl1"    (Nothing :: Maybe Double)  (fromRDFLabel (TypedLit "1.23" xsdFloat)) -- invalid input 
   , testEq "fconv:fail sn1"     (Nothing :: Maybe ScopedName) (fromRDFLabel l1)
   , testEq "fconv:fail qn1"     (Nothing :: Maybe QName)      (fromRDFLabel l1)
   , testEq "fconv:fail qu1"     (Nothing :: Maybe URI)        (fromRDFLabel l1)
   , testEq "fconv:fail triple"  (Nothing :: Maybe (ScopedName, ScopedName, Int)) (fromRDFTriple t01)
                                     
     -- basic string tests
-  , testEq     "tconv:emptystring1"  (Lit "" Nothing)    ""       -- want to try out IsString so do not use testToConv
+  , testEq     "tconv:emptystring1"  (Lit "")    ""       -- want to try out IsString so do not use testToConv
   , testConv   "emptystring2"        ""                  Nothing    (""::String)
   , testConv   "char"                "x"                 Nothing    'x'
   , testToConv "l1-1"                "l1"                Nothing    l1
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke  
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke  
 --  All rights reserved.
 --
 --  This file is part of Swish.

tests/RDFQueryTest.hs

 --------------------------------------------------------------------------------
 -- |
 --  Module      :  RDFQueryTest
---  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke
+--  Copyright   :  (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011, 2012 Douglas Burke
 --  License     :  GPL V2
 --
 --  Maintainer  :  Douglas Burke
 u_dt  = Res q_dattyp
 
 l_1, l_2, l_3, l_4, l_5 :: RDFLabel
-l_1   = Lit "l1" Nothing
-l_2   = Lit "l2" (Just $ langName "fr")
-l_3   = Lit "l3" (Just q_dattyp)
-l_4   = Lit "l4" (Just q_dattyp) -- was: (Lang "fr")
-l_5   = Lit "l5" (Just rdfXMLLiteral)
+l_1   = Lit "l1"
+l_2   = LangLit "l2" $ langName "fr"
+l_3   = TypedLit "l3" q_dattyp
+l_4   = TypedLit "l4" q_dattyp
+l_5   = TypedLit "l5" rdfXMLLiteral
 
 b_1, b_2, b_3, b_l1, b_l2 :: RDFLabel
 b_1   = Blank "1"
 
 --------------------------------------------------------------------------------
 --
---  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke  
+--  Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin,
+--    2011, 2012 Douglas Burke  
 --  All rights reserved.
 --
 --  This file is part of Swish.