You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the colonnade library, in the Colonnade.Encoding, I use doctest. This causes some of the code examples to end up uglier than they could have. For example (in the fromMaybe docs):
>>> :{
>>> let owners :: [(Person,Maybe House)]
>>> owners =
>>> [ (Person "Jordan" 18, Nothing)
>>> , (Person "Ruth" 25, Just (House Red 125000))
>>> , (Person "Sonia" 12, Just (House Green 145000))
>>> ]
>>> :}
However, this is unsightly, and I would never expect anyone to want to run it from ghci. I would much rather write this as:
owners:: [(Person,MaybeHouse)]
owners =
[ (Person"Jordan"18, Nothing)
, (Person"Ruth"25, Just (HouseRed125000))
, (Person"Sonia"12, Just (HouseGreen145000))
]
I know that doctest's main goal is to compile things that would be run in ghci. But, being able to run code blocks would go a long way in making documentation more readable.
My (probably bad) take on a solution would be to add a flag for supporting code blocks. If this were enabled, some sketchy heuristic-based algorithm could turn a code block into an equivalent ghci let-binding before handing it to ghci. I would be willing to give this a try, but I'd also really appreciate any feedback on the idea.
The text was updated successfully, but these errors were encountered:
I'm still interested in trying to do this. Can anyone provide feedback on the approach I outlined or comment on the likelihood of this being merged in if I wrote in?
@andrewthad Wait a second, but you could already use multiline ghci commands and omit the starting >>> everywhere but in the first line. You still need it to be a comment though. Is this not enough?
Unfortunately, it does not work with properties. There is an issue #131 about it.
Eventually, I realized that was possible, and that's the convention that I've adopted in my libraries. I still think that it wastes space, but it's an acceptable workaround.
In the
colonnade
library, in the Colonnade.Encoding, I use doctest. This causes some of the code examples to end up uglier than they could have. For example (in thefromMaybe
docs):However, this is unsightly, and I would never expect anyone to want to run it from ghci. I would much rather write this as:
I know that doctest's main goal is to compile things that would be run in ghci. But, being able to run code blocks would go a long way in making documentation more readable.
My (probably bad) take on a solution would be to add a flag for supporting code blocks. If this were enabled, some sketchy heuristic-based algorithm could turn a code block into an equivalent ghci let-binding before handing it to ghci. I would be willing to give this a try, but I'd also really appreciate any feedback on the idea.
The text was updated successfully, but these errors were encountered: