I am trying to work from a w3c spec to Haskell type system. Being new to Haskell I'm a little stuck. Could anyone help?
I have a data type called Atom
, which is defined as
data Atom = Atom {
atomValue :: String
, atomType :: String
, atomDataType :: Maybe String
, atomLanguage :: Maybe String
} deriving (Show)
I want an IRI type that enforces atomType = "iri"
in the Atom
and bnode
with atomType = "bnode"
etc
An RDF triple consists of three components:
the subject, which is an IRI or a blank node
the predicate, which is an IRI
the object, which is an IRI, a literal or a blank node
An RDF triple is conventionally written in the order subject, predicate, object.
The set of nodes of an RDF graph is the set of subjects and objects of triples in the graph. It is possible for a predicate IRI to also occur as a node in the same graph.
IRIs, literals and blank nodes are collectively known as RDF terms.
CodePudding user response:
I don't have any idea of w3 specs. But reading the definition, an initial approach would be
data RDF = RDF Subject Predicate Object
data Subject = SubjectIRI IRI | SubjectBlank
newtype Predicate = Predicate IRI
data Object = ObjectIRI IRI | ObjectLiteral | ObjectBlank
newtype IRI = IRI Text -- up to the documentation and IRI is an Unicode string with some properties
In general having a type with String
storing the type is a bad Idea, because you are not getting any benefits from the type system.