

Show HN: Haquery – jQuery for Haskell - friendly_chap
https://github.com/recurziv/haquery

======
friendly_chap
Hi, author here.

Maybe "jQuery for Haskell" is not too descriptive: it is a pure Haskell html
dom manipulation tool, mainly useful for templating and/or scraping.

It uses the same selectors and API as jQuery, the only deviations are due to
immutability (eg. if you modify a selection, the original graph will not be
updated of course, so you have to use "alter" or something similar).

Edit:

Feel free to send a pull request or suggest any changes. The time I poured
into the library was mainly focused on getting even the most complex nested
selectors to work, because I felt that is the lion's share of the work.

~~~
tych0
Cool! I have a similar project, based on lift's CssSel's (which are sort of
based on the jquery syntax):
[https://github.com/tych0/hquery](https://github.com/tych0/hquery)

I've been playing around with making a DSL vs. using string based selectors,
and I've had little success coming up with something sensible. Have you
thought about this at all?

~~~
friendly_chap
I will check your repo too. If you have problems due to similar naming let me
know and I will change it.

Regarding the selector DSLs, I also went with the string solution, however I
translate all selectors to a recursive ADT which could be used directly.

Maybe we should unite our powers ;)

~~~
tych0
Nah, no issues with naming, mine was just a pet project to pick up a bit of
haskell.

R.E. uniting forces, yeah! I looked through your code a bit, and it looks like
we have the same underlying idea (yours seems a bit less convoluted than mine,
though :-). I'm not really actively using hquery for anything more than a
static site generator I wrote with it, but I wouldn't mind spending a few more
hours/week on haskell code.

~~~
friendly_chap
Seems like we are on the same page, I also test drived this library with a
static site generator =).

I was really surprised that there are no more templating languages for Haskell
given the availability of the mighty parsec.

I am following you on github, stay in touch.

------
alipang
Looks cool. I feel like you should try and integrate with existing Haskell
concepts. Maybe you'd have to make small changes in the design decisions
compared to jQuery, but honestly, using the typical Haskell abstractions
things just seem to be "right" somehow.

Queries could easily be modelled with the list monad. Add the stateT
transformer for effects. Add lenses for niceness. (Lenses could really
beautify the internal implementation as well me thinks).

I'd love to hear about some of your design choices making this.

~~~
friendly_chap
Thank you! I definitely agree with you regarding the idiomatic solutions.

However, the only defense I can come up with (not that I really want to excuse
myself) is this is part of an effort (Hakit) to make Haskell web development
accessible to HS beginners. I was a beginner myself when I started Hakit, a
web toolkit, and I was overwhelmed by the seemingly complex Haskell APIs. So I
tried to build a complete toolkit while forcing the users learning as few
Haskell concepts as possible, without writing exceedingly ugly code.

I will surely try to make this more appealing to Haskell ninjas too though.

~~~
jhartikainen
Interesting, as a web dev I agree that getting into Haskell can be a bit
tricky due to exactly what you said... However, I feel that if you remove the
Haskelly parts from Haskell it's no longer really what makes it so great. I
think focus should rather be more on writing better guides (many of the
existing ones are not very "hands on" so you can't get straight to doing what
you want - web development - even though it's doable).

However, that being said, I look forward to seeing how this progresses and
anything else you may have in store.

~~~
friendly_chap
As a beginner I got into Haskell for the basics - generics done right, ADTs,
typeclasses, very nice syntax, crazy good list operations etc

My reaction to monads & transformers was: "I never asked for this."

I got used to them in a couple of weeks but I know multiple people personally
who couldn't grasp them in months. I try to provide them with a toolkit to
flex their muscles on and be productive with.

------
egonschiele
This looks cool. There's another package for generating html called blaze-
html. It's fast and elegant, I like it a lot:
[http://jaspervdj.be/blaze/](http://jaspervdj.be/blaze/)

For parsing HTML, I wrote a library called HandsomeSoup. It adds CSS selectors
to HXT, which provides everything you need for parsing HTML:
[https://github.com/egonschiele/HandsomeSoup](https://github.com/egonschiele/HandsomeSoup)

~~~
carterschonwald
Blaze is pretty cool. The same author has iterated on a neat static site
generator lib that's now in its 4th iteration over the past five years.

Likewise, for serious Haskell webdev, Snap, or perhaps HappStack or Yesod, are
the tools to consider for general Haskell backed web engineering

------
Egregore
There is also Haquery framework for Haxe language, at
[http://haquery.com/](http://haquery.com/) As far as I know it's a client
server framework (Haxe can be compiled to Javascript and to PHP)

------
LukeHoersten
This might be a nice way to get around the JS-FFI burdening things like Fay
and GHCJS which compile Haskell to JS.

------
Ixiaus
Why parsec over attoparsec?

