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

servant-docs: Fix docsWith. #124

Merged
merged 2 commits into from
Jun 17, 2015
Merged

Conversation

kantp
Copy link
Contributor

@kantp kantp commented Jun 16, 2015

Hi,

thanks for this nice library :)

I noticed that the enpoints vanished from the documentation when adding extra info via docsWith. This pull-request fixes that.

Best,
Philipp

When adding extra info using using docsWith, the responses vanished from
the output. This was due to combineAction being left-biased, and
docsWith combining the extra info with the enpoint (in that
order). Flipping combineAction solves this.
@alpmestan
Copy link
Contributor

Hello Philipp and thanks for the PR!

Upon seeing your PR, @jkarni realized that much of that "information merging logic" seems a bit fragile. We're wondering whether we could actually revamp some of that logic and find a smarter, sound & principled solution to this.

So while your PR fixes the problem you were having, we're kind of afraid that someone else might encounter a similar dark corner tomorrow because of a similar problem.

I would be much more comfortable having a lossless information merging logic, where we never drop any bit of information.

tl;dr: thanks for fixing the issue you found, we might merge it as is or use this opportunity to try and find a more robust merging strategy =)

@kantp
Copy link
Contributor Author

kantp commented Jun 16, 2015

Hi Alp,

thanks for the quick reply.

I'm actually having some very similar 'lopsided merging' code in one of my own projects, so I would be very interested if you can come up with something more robust, or to participate in a brainstorming phase. Of course, if I have a sudden flash of wit and find something, I'll let you know as well.

Best,
Philipp

@alpmestan
Copy link
Contributor

Would you mind just adding a little test for a minimal-version of the problem you encountered and which gets fixed by this PR? Just to make sure a future rewrite gets it right too.

@kantp
Copy link
Contributor Author

kantp commented Jun 16, 2015

Sure, I'll do that.

Make sure that no information is lost when providing additional
information via docsWith. With the current left-biased implementation of
combineAction, this can happen if the function arguments are in the
wrong order.
@kantp
Copy link
Contributor Author

kantp commented Jun 17, 2015

The CI failure seems to be unrelated to the commit (apparently, the random package failed to install).

@kantp
Copy link
Contributor Author

kantp commented Jun 17, 2015

I also gave the problem of making the merging more robust some thought.

One thing that I think should be possible is to use indexed types, as in REPA (http://www.cse.unsw.edu.au/~benl/papers/guiding/guiding-Haskell2012-sub.pdf). You'd have two different Actions, let's call them Action A and Action B, where Action A is a complete Action containing all information derived from the API datatype. An ExtraInfo would contain Action B, which cannot have information about Responses.

combining functions would have signatures Action A -> Action B -> Action A and Action B -> Action B -> Action B, but not Action A -> Action A -> Action A, so the type system would prevent you from accidentally discarding information by providing arguments in the wrong order, or by trying to combine two Actions with Reponses.

It might be overkill, but servant already does a lot of magic on the type level, so maybe it fits in. What do you think?

@alpmestan
Copy link
Contributor

Re: the build failure, I've just restarted it because it seems to a random timeout or something rather than an actual problem.

@alpmestan
Copy link
Contributor

There you go. The build succeeds. So we're going to merge this and make a bugfix release in the upcoming days and then we're probably going to end up with a rewrite in 0.5.

One of most promising directions here is to just rely on something like pandoc-type's Block ADT. This is strictly more principled, tested and richer than our little ADTs and very simple to understand. We even have servant-pandoc to guide us in the rewrite, @jkarni =)

Julian: good to merge?

@jkarni
Copy link
Member

jkarni commented Jun 17, 2015

@alpmestan yup on my end.

@kantp hi! and thanks!

alpmestan added a commit that referenced this pull request Jun 17, 2015
servant-docs: Fix docsWith.
@alpmestan alpmestan merged commit 74423fe into haskell-servant:master Jun 17, 2015
@alpmestan
Copy link
Contributor

Thanks @kantp!

@kantp
Copy link
Contributor Author

kantp commented Jun 17, 2015

You're very welcome, thanks for handling this so quickly, and for writing the library in the first place!

@jkarni Hi there, hope to see you at the next meetup!

@christian-marie
Copy link
Contributor

Cherry picking this.

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

Successfully merging this pull request may close these issues.

None yet

4 participants