0
HTML结构命名策略考虑以下Haskell的类型,描述一个HTML文档的基本结构:用于描述在Haskell
data HTML = HTML HTMLElement [HTMLElement]
data HTMLElement = HTMLElement HTMLElementTagname [HTMLAttribute]
data HTMLElementTagname = HTMLElementTagname String
data HTMLAttribute = HTMLAttribute (HTMLAttributeKey, HTMLAttributeValue)
data HTMLAttributeKey = HTMLAttributeKey String
data HTMLAttributeValue = HTMLAttributeValue String
我的问题主要是关于这个结构的适当的命名策略。在最后一个类型HTMLAttributeValue
中查找示例,它清楚地显示了定义类型的层次结构,但仅使用了我正在使用的驼峰式约定。没有人会让别人称之为value_of_html_attribute
,只是为了举一个例子。这可能被认为是有问题的。
另一个命名看起来是这样的:
data HTML = HTML HTML [Element]
data Element = Element Tagname [Attribute]
data Tagname = Tagname String
data Attribute = Attribute (Key, Value)
data Key = Key String
data Value = Value String
然而,这会污染全局命名空间。例如,Key
或Value
的类型可能适用于其他数据结构的代码中的其他位置。然而,后面的例子对我来说看起来更具可读性,而第一个例子似乎相当迂腐。
你将如何实现这一点?