I've been doing some work on Hoogle 4 over the last week while I've been away from a computer. Lots of cool new ideas, some paper code, and other goodies - will probably be a few weeks before I start to crank out implementations and improvements get seen on the main Hoogle site, and perhaps 2 or 3 months before Hoogle 4 starts to take shape.
Anyway, one thing Hoogle needs to do is to output a web page, and at the moment it does that by reading in text files, and writing them out. To do a typical search page it shoves out a standard prefix, a top bit, the answers and a suffix. Only the answers are generated on the fly, the others are included in. Of course, this means that the HTML is in 4 places, and the reusability is poor (files are chunks of text, not functions). The pages also have small tweaks to them based on dynamic data - for example the title of the page is the search query. To accomodate this I had to add $ replacement, so $ becomes the search query. Messy, and not very general.
So to answer all this, I devised .ths - Textual Haskell Source. Currently you have .hs (source code is the main thing), .lhs (comments are the main thing) and now you have .ths (text is the main thing). Lets start with an example:
> showHtml :: String -> String
> showHtml search = pure
[html]
[head]
[title]<% search %> - Hoogle[/title]
[/head]
Note that in this example I am escaping the code (with > ticks), and the text is just the main bit. I also have <% code %> which is substituted inline.
I can also do more advanced things (naturally)
> showList :: FilePath -> [Bool] -> IO String
> showList filename items =
> src <- readFile filename
The length of <% filename %> is <% length src %>
And the booleans are
<%for i = items %> <%if i %>ON<%else%>off<%end if%><%end for%>
I have all these bits implemented, and hope to make a release in a few days. I kind of have to release, because the current darcs version of Hoogle will be using them in a few days anyway.
And of course, since all this stuff is Haskell, its easier to compose, call as functions, etc.
Thoughts or comments?
Subscribe to:
Post Comments (Atom)
4 comments:
Thinking down the road, will Hoogle be internationalized and localized? If so, where would you put the translated strings?
I doubt that Hoogle will be localised - the amount of text that is actually in the Hoogle interface is tiny, and as long as you've used Google you can probably figure it out without any text. (In fact, the only words on the front page that actually matter and Tutorial, Manual and Search).
If the haddock documentation got localised, and the other aspects (Hoogle manual etc) then I might consider it.
Having said that, once I have moved fully to .ths, then I can probably tweak it to do translated strings without much work.
Hmmmm... It feels like you've rediscovered the square weel. :-)
Taking the detour via plain text seems a bit overly general. Why don't go for HTML/XML directly instead? I think you would be better off with using hsx which supports Haskell mixed with XML. It seems to be exactly what you're after.
Thanks for pointing that out, sadly it says it requires GHC for the output, which makes it a total no for me (Hoogle is developed in Hugs, and will be released in Yhc, and runs on a web server in GHC) - however pattern guards are a simple syntactic transformation so I would probably be able to fix it easily enough.
Next problem is that I can't find any examples of a single file that I might use this on. Without that I can't know what it can do, and what it can't.
I also want more than just HTML, I will want CSS, Javascript and other little bits too. Without knowing how hsx works, I can't know if what i want to do is feasible.
However, it does look kind of promising, and in the same direction.
Post a Comment