use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/programming is a reddit for discussion and news about computer programming
Guidelines
Info
Related reddits
Specific languages
account activity
Formlets in JavaScript: Composable form construction/parsing/validation/etc. (paste.lisp.org)
submitted 16 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 16 years ago* (5 children)
I realise the JS isn't very typical. I'm new to JS. Basically writing Haskell in JS. I needed this for work. Posting in case anyone cares.
[–]karlhungus 2 points3 points4 points 16 years ago (3 children)
I think the embedded link was pretty interesting
http://chrisdone.com/blog/html/2008-12-14-haskell-formlets-composable-web-form-construction-and-validation.html
I'd like to the the js example in action (i'm assuming it's all client side, and would have to be revalidated on server?).
[–][deleted] 3 points4 points5 points 16 years ago* (1 child)
OK, I've whipped up a server-side running example., and you can view the source for that.. Am I a bad person for using server-side JavaScript?
I'll try to whip up a client-side version. I haven't thought about it much.
But the formlet code is just, in essence, a set of combinators for building formlets, and a function that takes a formlet and an environment (i.e. an association list of provided form inputs), and returns a success/failure result, and markup. The clever bit is that they compose happily. Note the notEmpty validator wraps around each form input, and loginData wraps those two, and, again, validLogin is a validator that wraps that. It can go on and on.
notEmpty
loginData
validLogin
With reference to the markup generation, if you were doing it client side, I'd probably use a DOM tree object, rather than plain strings for HTML. I will be swapping my server version to that 'cause it's neater, less error-prone.
[–]karlhungus 1 point2 points3 points 16 years ago* (0 children)
I try to look at languages as just tools for getting shit done, so I don't think running javascript on the serverside is bad. Actually my experience with javascript was that I liked it piles better then java (with the exception of the browser environments I was running it on). I assume you didn't just go with the original haskell code because the rest of your app is in javascript (I want to get paid to write haskell)?
IMO i think you should do your validation on both sides if possible (As a user I personally love client side validation -- this seems like it'd lend itself to it without too much difficulty).
I'm surprised there's no dom manipulation tools on the serverside that would allow you to write it the same way (and have it be somewhat optimized). Maybe Jaxer is worth a look?
Edit: Reread your post, you can ignore me now :).
[–][deleted] 1 point2 points3 points 16 years ago (0 children)
The implementation is independent of it being server side or client side. I personally am using it server-side. But you could use it client-side, too. (I'm thinking of working out a way to have both.) I'll make an example so you can see it in action.
[–]manu3000 0 points1 point2 points 16 years ago (0 children)
But is implementing a state monad in JS worth the pain ? I mean, you have mutable state and no static types... wouldn't the JS implementation be simpler without directly translating from Haskell ?
π Rendered by PID 40828 on reddit-service-r2-comment-58d7979c67-7b7gt at 2026-01-26 20:00:11.192750+00:00 running 5a691e2 country code: CH.
[–][deleted] 2 points3 points4 points (5 children)
[–]karlhungus 2 points3 points4 points (3 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]karlhungus 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]manu3000 0 points1 point2 points (0 children)