haskell 类型挑战赛

bvjveswy  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(130)

我正在尝试从w3c规范到Haskell类型系统。作为Haskell的新手,我有点卡住了。有人能帮忙吗?
我有一个名为Atom的数据类型,其定义为

data Atom = Atom {
    atomValue :: String
    , atomType :: String
    , atomDataType :: Maybe String
    , atomLanguage :: Maybe String
} deriving (Show)

我希望IRI类型在Atom中强制atomType = "iri",在atomType = "bnode"中强制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.
pftdvrlh

pftdvrlh1#

我对w3规范没有任何概念,但是阅读定义,initial 方法将是

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存储类型是一个坏主意,因为您不会从类型系统中获得任何好处。

相关问题