8 ms·
Show HN: IHP, a batteries-included web framework built on Haskell and Nix
- underdeserver 6y agoLooks really cool! I like the neat UI, auto refresh and everything. I even skimmed the 27-minute demo video (that's a bit long guys), but I don't see any reference to testing, making this a nonstarter for me.
- _query 6y agoHey, thanks for your feedback! :) We're internally using hspec for testing our code. We're going to add some more documentation on using hspec with IHP soon.
- hendi_ 6y agoImportant bit missing from the title: this is using Haskell (and Nix). IHP is supposed to become the Django/Rails/Phoenix of Haskell. I've been using Django professionally for since 2013, but have started using IHP a couple of weeks ago. It's still quite early but with surprisingly few rough edges, i.e. the developer ergonomics are much better than I expected. It has great documentation that is improving rapidly (as opposed to many other Haskell libraries, which provide little more than API docs or even just the typed function definitions) and offers a refreshing take on database management and migrations. Some of its killer features: - HSX, a JSX-like template language that looks like HTML while providing type safety - Auto live reloading without the need to setup anything - Documentation with examples: it lets you query the database without learning about monads - it defines |> for you ;-) - type-safe, composable SQL queries: projects <- query @Project |> filterWhere (#userId, userId) |> filterWhere (#deleted, False) |> orderBy #createdAt |> fetch
- deleted 6y ago[deleted]
- dang 6y ago(We put those in the title after this was posted.)
- throwaway_pdp09 6y agoI get the type-safe part, assuming it means the eventual query will produce a predictable result set compatible with wherever it's being read into (I'm not a haskeller), but a) SQL is easy enough to learn syntactically b) there are good reasons not to create dynamic SQL; it's better to write it such that a query plan can be cached (for scalability). Which is very likely possible here but is it done? I wonder if the person who wrote this understands SQL to sufficient depth. Not saying either way, just asking.
- hendi_ 6y agoYour point a) is moot, this is not what this is about. When writing manual SQL nothing stops you from doing `SELECT * FROM persons WHERE age > 'eighteen'` (the `age` field is a number, obviously). Coming from Django I was often bitten by `Person.objects.filter(age__gt=trashhold) # boom!` (note the misspelled variable "threshold") or, if you prefer manual writin SQL: `Person.objects.raw("SELECT * FROM persons WHERE age > {}", trashhold) # boom! as well`. (Admittedly this is unrelated to type safety, just a disadvantage of Python being interpreted, but still something that Haskell/IHP protects me of.) Regarding b), yes there are good reasons for prepared statements. I won't go into your argument "for scalability" (premature optimization cough) but cached query plans aren't perfect either: data and data typologies change, and so does the optimal query plan. See https://blog.soykaf.com/post/postgresql-elixir-troubles/ https://blog.soykaf.com/post/postgresql-elixir-troubles/ for a blog post about Elixir/Phoenix/Ecto users being bitten by that. > I wonder if the person who wrote this understands SQL to sufficient depth. Not saying either way, just asking. I did not write the IHP code, just the above comment. But I've read many of CJ Date's books and have a good grasp on the relational model, and of SQL too. I simply don't see things as black/white, there are certain queries where I do prefer prepared statements and functions, or PL/pgSQL even, then there are ones where I use an external .sql file to keep things tidy. But most of the time (especially in the user facing part of a web app) I like my ORMs or SQL DSLs.
- necovek 6y agoUnless you've got `trashhold` actually defined, tools like flake8 would protect you from that mistake with Python. Using type hints would also protect you from using variables with incompatible types with a better designed API (Django's ORM API is anything but). As for SQL performance, I've usually only worked with up to hundreds of millions of rows per table, and the most important thing at that scale was to attempt to keep indexes in memory cache (that improves or degrades the performance by a couple of orders of magnitude). I haven't had a need for query plans to be cached, though I did use subselects to force particular query plans when needed (which has the similar problem of query plans not being the most efficient ones when data evolves sufficiently).
- sradman 6y ago> IHP is supposed to become the Django/Rails/Phoenix of Haskell. And like these other server-side web frameworks, IHP is SQL centric. What sets it apart is the IDE integrated into the dev server. The IDE together with Nix allows IHP to be PostgreSQL only, avoiding out-of-band server installs and providing a UI for schema/model construction. This is an interesting option and seems to have appeal beyond Haskell enthusiasts.
- rckoepke 6y agoTo help me understand better, what would be an example of an "out-of-band" server install?
- sradman 6y agoI should have qualified it as "RDBMS" server install. Most new SQL-centric web frameworks support three Open Source RDBMS engines: 1. MySQL, 2. PostgreSQL, and 3. SQLite. SQLite is rarely considered appropriate (arguably) for the server-side deployment RDBMS but its value comes from being embedded in the language runtime or web framework so it is available during development. IHP includes PostgreSQL as a Nix dependency so it is as ubiquitous as SQLite in the developer environment. "Out-of-Band" is relative to the project dependencies. Using PostgreSQL in the development environment for say Rails or Django requires "out-of-band" installation, configuration, and management. Frameworks like Rails and IHP apply the schema/migrations to a live development RDBMS and read the Catalog Metadata to generate the classes/structs used as the Data Access Objects (e.g. ActiveRecord in Rails). The RDBMS, therefore, is part of the CI/CD pipeline. Other ORMs define their entities independent of the RDBMS. I think Java JPA and Apple Core Data work this way; the SQL DDL is generated from the Entity Model. YeSQL-style frameworks also require a live development RDBMS but they extract metadata from each prepared statement rather than catalog metadata for each table which is mapped to a class/struct.
- abathur 6y agoI think sradman means that Nix enables IHP to guarantee the presence of postgres, rather than relying on the user to ensure pre-requisites get installed. Edit: Gah. :)
- hopia 6y agoThe SQL composition seems really intuitive. I'm pondering whether it's worth the effort to port my Servant application to this or not.
- alexmingoia 6y agoWow! Love it. I use my own hand rolled framework but will consider switching to this.
- rckoepke 6y agoI really enjoyed your introduction. For the HN readers who enjoy summaries in the comments, they open with a 10-12 sentence introduction, but the second sentence sets up the core philosophy and primary value proposition: > Back in the early days of the web, when server-side rendering was still a thing, javascript was sprinkled here and there to make a few parts of your web app just a little bit smoother. It's "built on top of Haskell and Nix." The more detailed 20 minute introduction and documentation is located at: https://ihp.digitallyinduced.com/Guide/ https://ihp.digitallyinduced.com/Guide/ I think the "recipes" section provides some illuminating examples. The creators make the following claims about durability at the end of their introduction page: > Lots of frameworks are already gone a year after launch. Especially in the fast moving JS world. But don't worry about IHP. We have been using it at digitally induced since 2017. It's actively used by us and our friends and partners. Even without external contributors we will build new features and do periodic maintenance releases in the future. We have big plans for IHP and as a profitable and independent software company we have the ability to actually execute them over the longterm. I'm very skeptical of web frameworks / toolkits. While I only work on personal projects, I tend to try to use pure HTML first, then add CSS where needed, then add JS where needed, then add backend where needed - always striving to minimize the amount of the next layer. This project seems to be targeted to someone with my preferences. I'll definitely be keeping an eye on it, and poking around with it.
- Kinrany 6y ago> For the HN readers who enjoy summaries in the comments This was a good reminder that I should at least skim the article first. On the other hand I wonder if there's a way for HN/Reddit to help people write summaries in comments. (Perhaps even recursively!)
- fimdomeio 6y agoI think enough time has passed that we're collectively forgetting the good reasons why so many moved from server side rendering, which I would say it was mostly the difficulty in make complex uis. Then it became a trend, now going old school seems appealing. Anyway in my particular case if I had any project that was a good fit for server side rendering I would probably now go with php and some libraries but probably no framework. I've been looking at some "weirdly coded 90's style php projects". An while the code is a terrible mess there's also the magic that I can read everything that's happening pretty quickly because it's just there or in a file next to it and not hidden in a library and a sub-library with calls to functions that I never seen before.
- cies 6y ago> I would probably now go with php seriously? 2020 and you'd pick php for a greenfield project? and you mention this here, where we're discussing a project that provides: strong typing, typed safe queries, type safe templates, and more. interesting.
- radisb 6y agoI love when people are shocked because someone decides which tech to use based on the merits of the tech instead of what the current year tech fashion dictates. It's hilarious.
- tluyben2 6y agoOr, you know, simple things like being able to easily attract people. No matter how I prefer Purescript/Haskell/Ocaml/F#/k or even Idris (not practical but I like writing things in it); if I need people fast, PHP/C#/TypeScript are just a better bet (I am surprised how easy it is to find good people with these skills now; seems unemployment hit these as well?). But it depends on what you are doing ofcourse.
- cies 6y ago> if I need people fast Exactly, this is a real reason for not using the technologically superior.
- sdn90 6y agoGreat work! I wasn't able to find anything on deployment in the docs. What does it look like? I've been looking for a framework with the following requirements: - Functional-ish language - Statically typed with Result<T, E> error handling. - Garbage collected. - Compile time checked HTML templates, with autoformatter and IDE support (like working with JSX/TSX in VS Code). - Some kind of SQL DSL that has decent IDE support (like Ecto on Elixir, Diesel on Rust). This framework checks off more of those than any framework I've seen. I'll definitely be giving it a try.
- laobiz 6y agoDeployment documentation is WIP at the moment and will be released soon. In the future we want to release a Cloud where the deployment will be as easy as clicking a button and having it online in a few seconds :)
- t0astbread 6y agoBecause you mentioned Result specifically: I've recently seen a talk by Rich Hickey that (for me) made a pretty strong case against Result/Maybe/etc. and for union types instead. Maybe you'll find it interesting: https://www.youtube.com/watch?v=YR5WdGrpoug https://www.youtube.com/watch?v=YR5WdGrpoug
- tluyben2 6y agoFirst off, nice work! I always thought it is better to mix client/server rendering; the 'everything client' or 'everything server' both do not work for a large number of applications. So why not mix them. Unfortunately not much out there battery-included that consistently supports that model. I did not dive into IHP (I heard about it as the RoR for Haskell) but, after reading the introduction, I'm probably going to get depressed when I hear how you do the inevitable client-side stuff here; there is a really good opportunity to mix them as there is HSX and you can compile Haskell to JS. So there should be an opportunity to appoint, where supported, some (parts of) a page as serverside/clientside.
- _query 6y agoThanks for your feedback! :) We have been tinkering a bit with building something close to Phoenix LiveView with HSX. Hope we can show something in that direction later this year.
- tluyben2 6y agoThat sounds good; thanks for the response. Most stuff I do is in the middle between static/dynamic; needs solid SEO and prerendered parts for various reasons but also contains, for browsers that support it, quite a lot of dynamic elements. Now we just use asp.net/static-with-some-react but that is driving me bonkers.
- dgb23 6y agoStatic with some react sounds like a nightmare. One of the primary reasons why many moved to JS frameworks was to have a better separation of concerns and a single place where GUI logic resides. May I suggest you have a look at Next.js. It lets you solve this in a very ergonomic way. Maybe even for your existing project.
- tluyben2 6y agoYeah it is a nightmare; it is not my choice. It is the same ‘everyone uses it so we need as well’ type of thing thrown in by partners. Thanks for Next.js: I did not know it.
- huijzer 6y agoThis sounds awesome! I'm using NixOS for almost a year now and am still very pleased with it. It can take some time to get things to work, but when it works you'll never have to look at it again! My biggest problem with Haskell is usually getting the dependencies right. So, the Nix package manager seems like a good fit.
- xgenecloud 6y agoIHP includes a GUI to build postgres schema - this is really cool and much appreciated. Databases have been existing for ages now and so are the GUI tools to manage them. However, it's unfortunate that most web frameworks fail to provide functionalities like this. Working in similar space[1], I have been talking to many early customers. Right from somebody who knows enough programming to product managers to CTOs, the idea of having a GUI within web framework and to have CRUD APIs ready with just few clicks gives them an amazing head start in building web apps. Getting past this redundant phase of creating basic CRUD with no hassle means - they can devote their energies on the business side of things. It will not be wrong to imagine in few years this workflow will become a norm. [1] : https://github.com/xgenecloud/xgenecloud https://github.com/xgenecloud/xgenecloud
- tluyben2 6y ago> It will not be wrong to imagine in few years this workflow will become a norm. I hope so too but we had this in different forms since the early 80s already (maybe earlier) and it never got big for some reason.
- xgenecloud 6y ago>> we had this in different forms since the early 80s already Could you name them, happy to check them out.
- exdsq 6y agoI've just played about with this and love what I see so far. If anyone wants a small site set up and are willing to take a bet on this tech, let me know - I'd be happy to collaborate and see what this is like in prod :)
- revskill 6y agoSo as i see, this is like a Rails framework with static type checking. Best of both worlds ! I'd love to see a guide on integrating with webpack or any frontend tech in the stack.
- cassepipe 6y agoWhat's the difference with Elm?
- Kexoth 6y agoRegarding execution, Elm is for client-side rendering, whilst this is for server-side rendering. As a language, they're very similar, one could even argue that Elm is a subset of Haskell :-)
- erikw 6y agoNix seems to be heading toward a critical mass in Germany. I use NixOS for my work computer, and couldn't imagine using any other OS. I keep a LinkedIn search open for nixos, and almost all of the hits are German. I'm interested in what kind of an organization might try out something like IHP? I've had a tough enough time introducing Typescript and more functionally oriented patterns in my team, so my guess is that organizations that would seriously consider IHP probably have a significantly different corporate culture.
- metalrain 6y agoThis looks interesting. I like how your code generation seems to expose most of the structure for customization, but have you thought about having different customizable templates for code generation? Like generating just REST API for this table vs generating user visible views.
- _query 6y agoThis is something we plan to do in the future. We have been thinking about adding a plugin system, where the plugins can provide custom code generators to the dev environment :)
- carapace 6y agoSeems very interesting, and a move in the right direction. What's it like to debug when something goes wrong?
- steve-chavez 6y agoUsing Nix to handle dependencies(haskell, pg) in a framework is really cool! But would IHP work in Windows natively? AFAICT, Nix doesn't work in Windows unless you use WSL(and even here I'm not sure how smooth it is).
- _query 6y agoThanks for your feedback :) Running IHP with WSL works pretty well so far. Some of our closed-beta testers have been running IHP on windows. We even made a video to get people started easier on WSL: https://www.youtube.com/watch?v=fM0WTMLdmVw https://www.youtube.com/watch?v=fM0WTMLdmVw
- roebk 6y agoA Haskell project with docs, this is a pleasant surprise. I’ve been playing around with Phoenix recently and I’ve been missing a decent type system (Dialyzer is pretty bad). I know very little Haskell but this makes me want to dip my toes in.
- lvass 6y agoNitpick: Javascript is usually compiled.
- deleted 6y ago[deleted]
- duc16001 6y agotesing hnay
- duc16001 6y agolet's goooo