Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Run code blocks #146

Open
andrewthad opened this issue Jan 9, 2017 · 3 comments
Open

Feature Request: Run code blocks #146

andrewthad opened this issue Jan 9, 2017 · 3 comments

Comments

@andrewthad
Copy link

andrewthad commented Jan 9, 2017

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,Maybe House)]
    owners =
      [ (Person "Jordan" 18, Nothing)
      , (Person "Ruth" 25, Just (House Red 125000))
      , (Person "Sonia" 12, Just (House Green 145000))
      ]

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.

@andrewthad
Copy link
Author

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?

@kindaro
Copy link
Contributor

kindaro commented Feb 26, 2018

@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.

@andrewthad
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants