Skip to content

Commit f57dc3f

Browse files
Remove selector functions, require OverloadedRecordDot or pattern matching (#21)
1 parent 28e1d0e commit f57dc3f

1 file changed

Lines changed: 3 additions & 71 deletions

File tree

src/KDL/Types.hs

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@
99
Defines the types that make up a KDL document.
1010
1111
This module enables @-XNoFieldSelectors@, so none of the fields create implicit
12-
selector functions. Instead, use @-XOverloadedRecordDot@, or the functions
13-
provided by this module.
12+
selector functions. Instead, use @-XOverloadedRecordDot@,
13+
@-XNamedFieldPuns@/@-XRecordWildCards@, or explicitly pattern-match.
1414
-}
1515
module KDL.Types (
1616
-- * Document
1717
Document,
18-
docNodes,
1918

2019
-- * NodeList
2120
NodeList (..),
2221
NodeListExtension (..),
2322
NodeListFormat (..),
24-
fromNodeList,
25-
nodeListFormat,
2623

2724
-- ** Helpers
2825
filterNodes,
@@ -36,11 +33,6 @@ module KDL.Types (
3633
Node (..),
3734
NodeExtension (..),
3835
NodeFormat (..),
39-
nodeAnn,
40-
nodeName,
41-
nodeEntries,
42-
nodeChildren,
43-
nodeFormat,
4436

4537
-- ** Helpers
4638
getArgs,
@@ -52,32 +44,23 @@ module KDL.Types (
5244
Entry (..),
5345
EntryExtension (..),
5446
EntryFormat (..),
55-
entryName,
56-
entryValue,
57-
entryFormat,
5847

5948
-- * Value
6049
Value (..),
6150
ValueExtension (..),
6251
ValueFormat (..),
63-
valueAnn,
64-
valueData,
65-
valueFormat,
6652
ValueData (..),
6753

6854
-- * Ann
6955
Ann (..),
7056
AnnExtension (..),
7157
AnnFormat (..),
72-
annIdentifier,
73-
annFormat,
7458

7559
-- * Identifier
7660
Identifier (..),
7761
IdentifierExtension (..),
7862
IdentifierFormat (..),
7963
fromIdentifier,
80-
identifierFormat,
8164
toIdentifier,
8265

8366
-- * Span
@@ -99,9 +82,6 @@ import Data.Text (Text)
9982

10083
type Document = NodeList
10184

102-
docNodes :: Document -> [Node]
103-
docNodes = fromNodeList
104-
10585
{----- NodeList -----}
10686

10787
data NodeList = NodeList
@@ -137,12 +117,6 @@ instance Default NodeListFormat where
137117
, trailing = ""
138118
}
139119

140-
fromNodeList :: NodeList -> [Node]
141-
fromNodeList = (.nodes)
142-
143-
nodeListFormat :: NodeList -> Maybe NodeListFormat
144-
nodeListFormat = (.ext.format)
145-
146120
-- | A helper to get all nodes with the given name
147121
filterNodes :: Text -> NodeList -> [Node]
148122
filterNodes name = filter ((== name) . (.name.value)) . (.nodes)
@@ -223,7 +197,7 @@ getDashChildrenAt name = mapMaybe getArg . getDashNodesAt name
223197
-- mapM getArg (getDashNodesAt "foo" doc) == Just [Number 1, Number 2, Text "test"]
224198
-- @
225199
getDashNodesAt :: Text -> NodeList -> [Node]
226-
getDashNodesAt name = maybe [] (filterNodes "-") . (nodeChildren <=< lookupNode name)
200+
getDashNodesAt name = maybe [] (filterNodes "-") . ((.children) <=< lookupNode name)
227201

228202
{----- Ann -----}
229203

@@ -266,12 +240,6 @@ instance Default AnnFormat where
266240
, trailing = ""
267241
}
268242

269-
annIdentifier :: Ann -> Identifier
270-
annIdentifier = (.identifier)
271-
272-
annFormat :: Ann -> Maybe AnnFormat
273-
annFormat = (.ext.format)
274-
275243
{----- Node -----}
276244

277245
data Node = Node
@@ -319,21 +287,6 @@ instance Default NodeFormat where
319287
, trailing = ""
320288
}
321289

322-
nodeAnn :: Node -> Maybe Ann
323-
nodeAnn = (.ann)
324-
325-
nodeName :: Node -> Identifier
326-
nodeName = (.name)
327-
328-
nodeEntries :: Node -> [Entry]
329-
nodeEntries = (.entries)
330-
331-
nodeChildren :: Node -> Maybe NodeList
332-
nodeChildren = (.children)
333-
334-
nodeFormat :: Node -> Maybe NodeFormat
335-
nodeFormat = (.ext.format)
336-
337290
-- | Get all the positional arguments of the node.
338291
getArgs :: Node -> [Value]
339292
getArgs node =
@@ -400,15 +353,6 @@ instance Default EntryFormat where
400353
, trailing = ""
401354
}
402355

403-
entryName :: Entry -> Maybe Identifier
404-
entryName = (.name)
405-
406-
entryValue :: Entry -> Value
407-
entryValue = (.value)
408-
409-
entryFormat :: Entry -> Maybe EntryFormat
410-
entryFormat = (.ext.format)
411-
412356
{----- Value -----}
413357

414358
data Value = Value
@@ -442,15 +386,6 @@ instance Default ValueFormat where
442386
{ repr = Nothing
443387
}
444388

445-
valueAnn :: Value -> Maybe Ann
446-
valueAnn = (.ann)
447-
448-
valueData :: Value -> ValueData
449-
valueData = (.data_)
450-
451-
valueFormat :: Value -> Maybe ValueFormat
452-
valueFormat = (.ext.format)
453-
454389
data ValueData
455390
= String Text
456391
| Number Scientific
@@ -495,9 +430,6 @@ instance Default IdentifierFormat where
495430
fromIdentifier :: Identifier -> Text
496431
fromIdentifier = (.value)
497432

498-
identifierFormat :: Identifier -> Maybe IdentifierFormat
499-
identifierFormat = (.ext.format)
500-
501433
toIdentifier :: Text -> Identifier
502434
toIdentifier value = Identifier{value = value, ext = def}
503435

0 commit comments

Comments
 (0)