5 ms·
Ask YC: if Haskell is the hammer, what should be the nail?
Hi, guys. I've been thinking of learning Haskell, and so have been casting about for a good project to start in it.
I found a top ten list of Haskell projects (http://haskell-news.blogspot.com/2008/01/top-10-most-popular-haskell-programs.html) and it looks like things are sparser than I might have hoped.
Anyway, if one wanted to break into that top-ten list by using using Haskell's strengths, what are some kinds of projects that one would take on?
Also, if anyone would like to join me, that would only add to the fun.
- rcoder 18y agoPersonally, I think there are some very interesting possibilities for using Haskell in the highly-secure web application space. The most trivial example would be simply using the type checker to protect against SQL injection and cross-site scripting attacks by representing user input with a different type than query parameters or HTML output. I've also thought for a while that Haskell would be a great environment in which to implement a static analysis tool to check the security of existing application code. In particular, I think that the PHP community could really use an information-flow and type-checking tool external to the core runtime which could be used to run a quick "sanity check" over source code. The simplicity of the language (relative to, say, Ruby or Perl) makes it a prime target for parsing and analysis, and the large body of existing code in the wild makes for an interesting set of test cases.
- tptacek 18y agoThere's this meme about type checking defeating SQL Injection that I don't really understand. There are basically three situations I see injection problems recurring in modern web code: * The stupid cases where people are interpolating input strings directly into query strings, so that a query for "O'Neill" will accidentally break your SQL. * The not-so-stupid cases where column sorts and query builders pass limits, sort orders, and groupings directly from user inputs. * The cases where stored procedures resort to dynamic SQL. The first problem is solved not by better type checking, but by switching to parameterized queries, where the query string is parsed prior to argument binding. The second problem is solved by not passing SQL literals in and out of input. The third problem isn't even happening in the application's programming language. Which of these problems is handled well by application type checking? As for XSS attacks, I'm again skeptical. If the problem was as easy as type checking, you'd solve it trivially by output filtering everything from the database, neutralizing HTML metacharacters. It's not that easy: there are lots of times when you really do need to honor HTML in input.
- rcoder 18y agoYou're right that #1 is indeed just a matter of using the right API. (I actually blame the poor state of many database client libraries and tutorial docs for the proliferation of interpolated query params, but the point remains that it's basically a mechanical fix.) For #2, the problem is a bit trickier, but again, it just requires attention on the part of the developer. Given the limited use of stored procedures by most LAMP developers, I think that #3 may be the least critical, even if it is the most difficult to tackle with a simple code analysis tool. As you suggest, none of these issues are particularly hard to avoid via careful programming. The problem is that programmers often aren't careful, and when working in languages which offer "one-size-fits-all" string, array, and file types, they tend to just shove everything into and out of those containers without thinking about type or flow checking. Type checking isn't a panacea, but it can flag issues of either type 1 or 2 early, which gives developers a chance to catch themselves before they commit (or even worse, deploy) a potential security hole. Part of my motivation for this comes from reading a lot of unit tests and specs for webapp code. If you step back and think a bit, it becomes obvious that a lot of the test harness is simply devoted to type checking, and that the verbosity (and easy satisfaction of coverage metrics such tests provide) often mask otherwise glaring gaps in the actual test coverage.
- tptacek 18y agoI guess I'm asking, how does Haskell reduce the amount of effort required to write secure SQL? * It helps in the first case, but then, so do parameterized queries, which developers already have and are familiar with. * It doesn't help --- at least not elegantly --- in the second case. * It can't help in the third case, because that error is happening in the database itself. (By the way, not sure why injections in dynamic SQL in stored procedures would be least critical). I get you loud and clear that "even though it's easy to avoid these problems in PHP, developers don't". You're right. "Use good code" is not a solution for the problem of "bad code". But is Haskell? I like the idea of static analysis in Haskell.
- rcoder 18y agoWhere a static analysis tool can help is in flagging those cases where a developer might have made a bad assumption, and forcing them to reconsider that code point. Basically, it's a way to enforce some basic code review practices without requiring one of your senior developers to be able + willing to read over your junior devs' code. The whole point of programming is to automate those tasks that can be automated, right? So, let's automate the first-pass stage of a basic security audit as much as we can. To your specific points: * Parameterized queries are available in some cases, as you said, but don't work when you have to build some portion of the query (sort order, grouping, etc.) at runtime. Static tools can help flag such dynamic values as being tainted or clean, as well as help insure that resulting queries will be well-formed. * All that's necessary to extend your type checking to the database is to enforce the same level of discipline you do for built-in API functions. Just as static analysis tools need a signature for primitive functions provided by the runtime platform (syscalls for C, primitive library functions for PHP, etc.), your static checker could ensure that queries which used stored procedures checked at least the asserted type signature of those procedures. (SQL is pretty type-savvy, and most stored proc authors should be able to trivially provide type sigs for their code.) The advantage to using Haskell for all of this is twofold: * There are excellent existing parsing and graph algorithm libraries maintained by the Haskell community * Working in a strict, pure functional language makes you think in terms of mathematical theories, rather than stateful effects, which in turn tends to result in better, more deterministic code That being said, I think you could use OCaml, Lisp, or any number of other high-level languages to similar effect. The uniquely math-oriented world view of Haskell (and its implementers and users) does tend to lend itself to just the kind of defensible reasoning that you would want from a security-focused static analysis tool, though.
- SwellJoe 18y agoI've just started watching the Simon Peyton Jones videos on the subject (from OSCon last year), and I've been kinda thinking I might tackle some systems monitoring problems (I usually use Perl for that sort of thing...and most every other sort of thing, lately). I, too, have been struck a bit by how low-level most of the libraries and such are, at this point (then again, compared to CPAN almost every language has a dearth of high level libraries). And I'm still far too much of an amateur at the language to do much about it. But it is an interesting language, and probably useful to tinker with even if no useful code ever comes of it.
- rcoder 18y agoYou may find systems monitoring to be a bit challenging in Haskell if you're accustomed to Perl. By design, the normal POSIX abstractions that are so tightly integrated into Perl are held at arm's length in Haskell, if available at all; something as simple as forking a child process or switching effective UIDs will require far more code in Haskell than in Perl. That being said, if you want to be able to reason about system configuration states, and write concise deterministic rules that dictate the triggers for and transitions between between such states, Haskell may be worth some additional attention.
- eelco 18y agoI don't think that's necessarily true. Take a look at all the System.Posix modules: http://haskell.org/ghc/docs/latest/html/libraries/unix/System-Posix.html http://haskell.org/ghc/docs/latest/html/libraries/unix/Syste...
- rcoder 18y agoThat's exactly my point, though -- there's a standard module for POSIX integration, but it's not part of the language syntax itself. It's a subtle thing if you don't do systems code often, but it becomes apparent after working with Perl for a while how much of it really is a domain-specific language for UNIX systems operations. Haskell, as a general-purpose functional language, is always going to require just a few more keystrokes/lines of code to accomplish the equivalent system operations.
- quasimojo 18y agowhat isn't haskell for? i've been throwing it at everything from fastcgi programs to scrapers to scripting to systems stuff maybe the one place it isn't well suited is in the realm of throw-away quickies. haskell code takes longer to write. that doesn't mean you are writing a lot of code. i still see a role for perl/python in throaway scripts haskell has practically every meaningful cool concept in CS built in. it is the functional language (for now). it is very fast and as the number of cores rises, haskell's performance will start to leave traditional tools in the dust. with the new GC it will destroy erlang on its own turf. haskell takes time to learn and time to code. if you are in a rush, it is not for you. otherwise, haskell can handle almost any problem in any case, you can come to haskell or it can come to you. the next ten years will see functional concepts get weaved into every language.
- JulianMorrison 18y agoRight now, the area Haskell absolutely thrashes everything else is speedy and lightweight concurrency (it even stomps Erlang in the Debian Shootout). So if you can find a project that needs fluid responsiveness, multi-connection or or multi-CPU scaling, Haskell is the ideal tool.
- dhbradshaw 18y agoOkay, here's what comes to mind based on those criteria: an operating systems, databases, large numerical simulations, intensive graphical manipulations, mind-modeling. Do these sound right?
- JulianMorrison 18y agoIt's not really much use for OSes unless you're a research project, because the compilers target an OS and not bare metal. Also, it's slower than C on actual processing (about the speed of Java). So numerical stuff is out, unless the benefits of being parallel outweigh the benefits of being fast. (This may improve as the back-end optimization project shows results.) I think the perfect target would be any sort of massively multi-user network server.