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

Hakyll.Core.Compiler: added makeItems #350

Closed
wants to merge 2 commits into from
Closed

Hakyll.Core.Compiler: added makeItems #350

wants to merge 2 commits into from

Conversation

wrengr
Copy link

@wrengr wrengr commented May 23, 2015

I added a function makeItems which behaves like (mapM makeItem) but far more efficiently

@wrengr
Copy link
Author

wrengr commented May 23, 2015

Also added optionalField which behaves as a combination of field and boolField

@krsch
Copy link
Contributor

krsch commented Jun 1, 2015

The optionalField has already been suggested in #311. That implementation accepts Item a -> Compiler (Maybe String) which in my opinion is much better. That pull request was closed due to its simplicity. However maybe implementing optionalField at least in documentation would really help someone.

I don't quite understand when would you need to create a list of Items with the same identifier. Could you make an example? And is makeItems really more efficient than mapM makeItem?

@nagisa
Copy link
Contributor

nagisa commented Jun 1, 2015

@krsch #311 is still open.

@krsch
Copy link
Contributor

krsch commented Jun 1, 2015

@nagisa sorry, my mistake. Then this pull request might be a reason to merge #311.

@wrengr
Copy link
Author

wrengr commented Jun 1, 2015

I'm all for the type Item a -> Compiler (Maybe String); I just implemented the simplest thing I could get to work based on a quick look at how the other field operators are defined (esp., boolField). Even if it is "trivial", the fact that multiple folks have requested it, and that it wasn't immediately obvious how to implement it (I'm only using it as a -> Maybe String and I had to sift through the Hakyll source to try and figure out how the $if()$ stuff even works) suggests that, in fact, it isn't so trivial to the uninitiated. Honestly, I was surprised that it wasn't already included in the library.

As for makeItems, I have a lot of database-like pages. That is, many of my pages are generated from lists of records (e.g., 1, 2), and it's necessary to convert each pure [A] into some [Item A] for passing off to contexts, templates, etc. So far as I'm aware, the Itemness is irrelevant here, and makeItem/makeItems is the simplest way to have things typecheck. Performance-wise, makeItems is more efficient because it does not need to repeatedly call getUnderlying and because the monad does not interfere with the ability to fuse away intermediate lists. In theory, GHC might be able to optimize away the overhead of using mapM makeItem, but that's relying on compiler magic unnecessarily.

The ultimate issue behind both these extensions is that it seems like Hakyll is (currently) designed exclusively to handle one-off pages (e.g., 3, 4) and blogs, and so has little support for pages generated from non-blog databases.

@jaspervdj
Copy link
Owner

I think we should add something like boolField or optionalField, since this has been requested twice now.

I don't think something like makeItems is necessary though. It will confuse people more since it uses the same underlying identifier. If you want this sort of "advanced" behaviour, it's not that hard to write mapM makeItem. And the performance of mapM makeItem really becomes a bottleneck (which I doubt it will)`, you can implement it in your site?

@wrengr
Copy link
Author

wrengr commented Jun 2, 2015

No worries, I can implement makeItems locally :) It really shouldn't be a bottleneck (if it is, that's a separate problem imo), I just default to high-level say-what-you-mean operators whenever possible— both for performance reasons and for semantic clarity/concision.

@wrengr
Copy link
Author

wrengr commented Jun 2, 2015

Also, boolField is already present in the current version on Hackage; it's just optionalField that's missing

@jaspervdj jaspervdj closed this Apr 1, 2016
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.

4 participants