Haskell类型挑战



我正在尝试从w3c规范到Haskell类型系统。刚来哈斯克尔,我有点不知所措。有人能帮忙吗?

我有一个名为Atom的数据类型,定义为
data Atom = Atom {
atomValue :: String
, atomType :: String
, atomDataType :: Maybe String
, atomLanguage :: Maybe String
} deriving (Show)

我想要一个IRI类型,在Atombnode中强制atomType = "iri"atomType = "bnode"

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.

我对w3规格没有任何概念。但是阅读定义,初始方法应该是

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

一般来说,使用String存储类型是一个坏主意,因为您没有从类型系统中获得任何好处。

最新更新