-
Notifications
You must be signed in to change notification settings - Fork 234
--show-interface appears to be encoded in Json, but the doc part is raw Haskell show output! #920
Description
Try it yourself:
Consider the following example module:
module Example where
-- | I am a comment.
--
-- >>> I am an example.
-- I am the result.
c = undefined
Let us obtain a Json representation of its haddock:
% haddock --dump-interface=Example.interface Example.hs
% haddock --show-interface=Example.interface 2> Example.interface.json
% cat Example.interface.json | jq
What we will see is this:
{
"link_env": {
"$main$Example$c": "Example"
},
"inst_ifaces": [
{
"module": "$main$Example",
"is_sig": false,
"info": {
"description": null,
"copyright": null,
"maintainer": null,
"stability": null,
"protability": null,
"safety": "Safe",
"language": null,
"extensions": []
},
"doc_map": {
"$main$Example$c": {
"meta": {
"version": null
},
"doc": "DocAppend (DocParagraph (DocString \"I am a comment.\")) (DocExamples [Example {exampleExpression = \"I am an example.\", exampleResult = [\"I am the result.\"]}])"
}
},
"arg_map": {},
"exports": [
"$main$Example$c"
],
"visible_exports": [
"$main$Example$c"
],
"options": [],
"fix_map": {}
}
]
}
Everything looks nice and tidy, except that the doc section appears to be a show output. Upon inspection, indeed:
Haddock.Interface.Json
...
63
64 jsonDoc :: Doc Name -> JsonDoc
65 jsonDoc doc = jsonString (show (bimap (moduleNameString . fst) nameStableString doc))
66
...
I do not exactly understand what the bimap is doing, but I am certainly unhappy with the overall approach.
Why is it a problem:
I want to programmatically access the contents of haddocks. From the fact that --show-interface outputs Json, I had an impression that it promises cross language interoperability. But hardly can I make a use of the doc field as it is currently presented, with Haskell-specific syntax.
- At the very least, if my program is in Haskell, it means that I need to depend on a specific version of
haddock-library(from which, as I researched, the string originates) or maintain a duplicate of a 27 constructor long data type. - If my program is in another language, I am in for writing a parser for this same 27 constructor long data type.
- Actually, I am in for some trouble anyway, since
DocHis not an instance ofRead. But with Haskell, I could probably standalone derive it.
- Actually, I am in for some trouble anyway, since
What can be done:
I see two ways we can go from here:
A. Write a more comprehensive jsonDoc function, and even a jsonDocH function to accompany it.
- Pros:
- Everything is Json.
- Cons:
- If any program was somehow managing to use this field, it will break
- But recall that this field is currently not machine readable.
- If any program was somehow managing to use this field, it will break
B. Write or derive an instance Read DocH.
- Pros:
- The output does not change, thus backwards compatibility is 100%.
- Cons:
- Ugly.
DocHrepresentation may change at any time.- Hard to parse with other languages.
- Forces the dependency on
haddock-library.
C. Do nothing, wontfix.
-
Pros:
- Nothing has to be done.
-
Cons:
- Same as B.
I am anxious to hear from the maintainers. If there is consensus, I can craft a pull request in no time.