[Haskell-cafe] idea for ycr2js demo, actually meant for an in-house project. is this realistic?

Thomas Hartman tphyahoo at gmail.com
Mon Nov 26 13:47:05 EST 2007


As I mentioned in a previous post, I've been spending quite some time
trying to get live with ycr2js because there's a project it would be
useful for for my day job, as well as making another nice demo to add
to the list.

Basically, I have some functionality that does client-side filtering
of large html tables. It's pretty smart -- it can filter on multiple
columns, and the filter can be any javascript expression from String
-> Bool (to use haskell terminology in a javascript context). The
filter works by hiding rows that don't match the filter; it's built on
mochikit.

Unfortunately this is rather ugly from the user's perspective. You
have to type something like

x.match("my string")

into the search string or

(x > 5 && x < 7)

where x is some variable buried in the javascript.

I would like for the user to be able to enter search criteria in a
more intuitive "google" style

=skittles or (=~"mr. goodbar" and =~"15 grams")

so you need a parser that takes the search criteria and converts it
into a function from (String -> Bool)

This parser is relatively easy to build in haskell; I built it. It's
surely also doable in javascript, but not as nicely, easily, and
cleanly, and being a better haskell than javascript programmer as
well, I would rather generate the javascript from haskell.

So at any rate what I have is

-- parser from String -> (String -> Bool) (haskell)
-- working html/javascript built on mochikit that filters a
multicolumn table with multiple filter expressions. There is a
function here that takes a string and returns a bool, but it's icky,
doesn't recognize quoted strings, doesn't recognize boolean and/or or
parentheses. I want to replace it with a function generated from
haskell that does all of these things.

What I need is to combine these two components.

I'll try and post some minimal source code for the parser and the
javascript/mochikit stuff soon, and if this problem is tractable it
can become another example for ycr2js.

A possible reason why this wouldn't work is that when you're using the
ycr2js stuff, *everything* has to be generated; it doesn't play well
plugging in an existing javascript function with a generated one. I'd
be surprised if that was the case, but since I haven't actually
successfully generated any code yet i guess anything possible. At any
rate, if this sort of thing could cause issues please someone in the
know give me fair warning.

thomas.


More information about the Haskell-Cafe mailing list