18 ms·
Dhall: A Gateway Drug to Haskell
- superb-owl 4y agoI initially tried to learn Haskell by creating a small Physics programming project. It was fun, and I found some great math libraries, but eventually got frustrated by the slow pace and switched to Python. Specifically, the amount of time I spent debugging types and signatures was really frustrating, and often left me googling the same error patterns to figure out where my mistake might be. I'm excited to try out Dhall and see if it has a smoother onramp.
- zingplex 4y agoI love Dhall and have used it in production, but I will say that the documentation, especially for things like dhall-kubernetes, often leaves much to be desired. You may need to spend a bit of time reading the source code.
- Q6T46nT668w6i3m 4y agoMy experience has been similar. I found that Haskell struggles, from a usability perspective, when there isn’t a variety of diverse types in your program and/or your programs, by their nature, rely on the characteristics or behavior of machine types. It’s not impossible, of course. It just adds an unfortunate amount of boilerplate.
- DonaldPShimoda 4y ago> the amount of time I spent debugging types and signatures was really frustrating, and often left me googling the same error patterns to figure out where my mistake might be. In my experience, people often describe their first experience with expressive static type systems in terms of "fighting with the compiler" (or similar phrasing). I think this is due to a poor introduction to static type systems, often in university settings. A static type system has one purpose: to prevent you from running unsafe code. Every type error is just the compiler telling you "what you wrote isn't going to work". This isn't a fight; it's a conversation. You write some code, run the compiler, get back some errors, fix them, and run the compiler again. This process is repeated until your mental model of how the code should work is properly reflect in the code, as determined by the success of your compiler's type-checking. There are frequently two sources of frustration in this process: 1. A difficult-to-use type system. Some type systems are just obnoxious to use. (Older) Java required soooo much verbose typing. The resulting code would be difficult to read just because there was so much text on the screen. More modern Java is an improvement, but newer languages are often designed from the ground up to use type inference to alleviate your keyboard-typing obligation. Another form of frustration is what you mention: inscrutable error messages. Haskell is pretty well known for having type errors that are not obvious to newcomers, and that turns the programmer-compiler conversation into a frustrating experience. Again, newer languages are making lots of progress here. I think Rust does a great job with its error messages, for example. Hopefully this is something the Haskell developers will look more into. 2. An insufficiently expressive type system. If your type system is too limited, you'll have a hard time finding it particularly useful. If your types are "too big", they become unwieldy and unhelpful. Older languages frequently fared poorly in this metric, because "types" were meant primarily for memory optimization rather than programmer expressiveness. However, as our languages have become more user-centered, our type systems have become more expressive and, thus, easier to use to model data. Modern languages like Rust and Swift have taken a lot of inspiration from functional languages like Haskell and ML to provide type capabilities that are significantly more expressive than those in other languages. I think type system inexpressiveness is a big part of why some people prefer dynamically typed languages, like Python. They find that they have a difficult time converting their mental model of the data into an explicit type, and so they move to an ecosystem where they simply don't have to deal with that. Personally, I think this indicates the need for better expressive type systems and better type system onboarding to teach people how to use them effectively, because if you rephrase the static type proposition to those programmers as "Would you like to guarantee that erroneous programs are simply never run?", I imagine most of them would enthusiastically shout "Yes!"
- picozeta 4y ago> In my experience, people often describe their first experience with expressive static type systems in terms of "fighting with the compiler" (or similar phrasing). I think this is due to a poor introduction to static type systems, often in university settings. Maybe that was true 20 years ago, but most CS curricula offer mandatory (static) functional programming classes.
- DonaldPShimoda 4y agoDepends on the school culture, the professor teaching, the particular language being used... there are a lot of factors! I did both my undergraduate and MS in the past decade, worked in academic research for a few years, and am currently in a PhD program. At the schools I've been at and schools I know well due to friends/collaborators, I think what I said still tends to be true for mandatory ("core") classes. You are right, however, that students who choose to take an elective in a statically typed functional language are probably more likely to come away with a healthier relationship with their compilers, but this is only a portion of all students.
- sn9 4y agoI would be shocked if that were actually true. Maybe most top 10 programs do, but in general the variation in CS curricula is incredibly broad and includes tons of Java schools that only focus on imperative and OO paradigms with only passing mentions of functional programming in elective classes. I really have no idea if the data to support the claim even exists. One would probably have to manually comb through CS curricula to check. My suspicion is that it would not hold up.
- superb-owl 4y agoI fully expected to spend time "fighting with the compiler" when playing with Haskell. I think the bigger issue was that the errors I got back from the compiler were very hard to trace back to the code, or to a particular part of my mental model that must be at fault. And it didn't seem to get easier over time - i.e. the same pattern of error message would be due to totally different issues with the model/code. I'm not sure if this is just a fact of life about FP or Haskell, or if it's something that could be improved on.
- fn-mote 4y agoI also found that my initial understanding of the numeric types, based on a traditional imperative programming experience, was not sufficient. However - I now think that I understand Haskell's way of looking at numeric types and have not had this kind of problem for quite a while. I will certainly agree that Rust's error messages are 1000x better, if you're looking for something similar. After writing this comment I looked at TFA and I'd say read it and maybe even watch the author's talk on "why learning Haskell is hard". In spite of what I expected, the article addresses the ways in which Dhall is a good starting point. (Although readers should be aware that "Dhall is not Turing complete", which for most programmers is a bad thing.)
- agentultra 4y agoNeat article! Haskell does have escape hatches though! They're incredibly annoying to use: being both noisy and easy to spot. This forces developers to justify their use because it's going to be annoying to maintain. This is exactly what you want in an escape hatch! Not convenience but being easy to spot. If it's easier to do it the Haskell way then you're often on the right path. Going off the path is dangerous and some times necessary, so don't hide it and make it easy to miss!
- galaxyLogic 4y agoIn emergency break the glass -principle
- picozeta 4y agoIn my opinion Haskell's capabilities to help implement general-purpose SW (services, compilers, GUI, game-dev, systems) are way over-hyped. Sure, it's nice to implement parsers/compilers in it (see ̶N̶̶̶i̶̶̶x̶̶̶, Elm, DHall) and it's to some extent popular for backend web development, but I don't think the strong static type system is such an advantage as advocates want you to believe. Of course it's safer (and faster) than dynamic languages like Python (Ruby, JavaScript), but in my personal opinion, you don't gain that much if you compare it to something like Rust, Java or even Go. In particular the common abstractions (Monad, Applicative, Functor) are used very differently in different libraries (everyone seems to want to write her own DSL), so it's hard to get comfortable with third party libraries. Furthermore it's still the case, that there's not much really interesting SW made in it. Some years ago you could argue, it's because of familiarity, but (static typed) functional programming is part of CS curricula for at least 10 to 20 years now. Lastly it's just incredible hard to estimate runtime characteristics (clock-time, memory usage), because you never know which compiler optimizations kick in or not. It's a nice language, but again, I don't think it's such a panacea as proponents often tell you. And to be snarky: If Haskell is such an advanced language to make implementing reliable SW such a breeze, it should be part (maybe as a dependency) of more SW. EDIT: Nix is implemented in C++ as correctly pointed out in a comment.
- rowanG077 4y agoI only agree with the runtime characteristics point. It's very hard to get an idea of what is efficient or not sometimes. But on every other point I believe Haskell is magnitudes better for general software development then mainstream languages.
- amelius 4y agoPerhaps the ideal language is then a combination of two approaches: Haskell in the outer loops, Rust in the inner loops?
- marcosdumay 4y agoThe Python code using C libraries you get on machine learning is a nice model. There is no reason why you can't recreate it with Haskell + Rust. But it has one drawback that it's relatively slow to pack stuff to send between languages. On Python everything is so slow that this doesn't make much of a difference, but on the Haskell + Rust scenario you will want much larger library blocks.
- aranchelk 4y ago> Haskell is hard. More accurately: Haskell is particularly hard for a procedural programmer to learn in comparison to a new procedural language and the time spent learning prior to being as productive may be (from my experience) 30x. IMO, once learned, the type checking is so helpful, everything else seems hard. Also, learning the language is only half the battle as it’s much more difficult to establish for yourself good practices for common use cases like app development. You’ll find plenty of people using FP for specialized stuff that’s not relevant to the average working programmer. In looking for advice you may stumble across the promotion of peoples’ impractical pet projects, and without experience you won’t know it. If you can budget the time to learn the language and then build a couple poorly structured apps that you’ll come to hate, expect very smooth sailing after.
- eterps 4y agoTo be honest, after having learned other FP languages like OCaml/ReScript, F#, Elixir, Gleam and Elm, I still find Haskell baffling. Not necessarily writing it, but I find reading someone else's Haskell code insanely difficult. It will take many more years before I get comfortable with that.
- yodsanklai 4y agoI agree. I'm quite experienced with FP, but I find Haskell hard, or at least impractical. Not necessarily because of abstractions, but some design choices make programs hard to read for no good reasons. > but I find reading someone else's Haskell code insanely difficult. It's true for expert Haskellers as well.
- jpittis 4y agoNot to mention large parts of the community using a pointfree, single character variable naming style that's hard to read. If Haskell could consistently be written in a more predictable style, that would be much more suited to collaboration IMO.
- 4y ago
- benreesman 4y agoI’m currently a bit overweight, like maybe 10-15lbs. This is because I have some combination of bandwidth-consuming and focus-consuming things going on that results in me not doing an obviously correct thing: get the fuck back in shape. Every hacker in the peanut gallery deep-down knows that they should know Haskell and Lisp well. They resent the fact that their job or personal life or whatever doesn’t leave room to get serious about computation theory. And they vent this frustration endlessly on people lucky enough to have had the bandwidth at the right time to thoughtfully contrast computation with physical computing machines (the only person I know to stomp Lemire in AVX is a GHC hacker). I’m kinda fat because I haven’t fixed it yet. People don’t know Haskell and Lisp well because they haven’t fixed it yet. Neither is an appealing look.
- sudosysgen 4y agoMeh. I have had the time to learn a fair amount of Haskell and do a few projects in it (mainly interpreters). It's a fun language in some ways, and it was nice to know how to use it because it expands your ways of thinking, but beyond that it's not terribly useful, and I don't think that it's much better at that than other functional programming languages. Learning about the type-system is neat but IMO not as perspective changing as "getting" purely functional programming. However, as an actual tool to do actual work, I really don't see why you would go about it for anything but very specific projects.
- feanaro 4y agoI seriously suspect there is a bimodal distribution are play here, because I would love to use Haskell, or something like it that's possibly more powerful like Idris, wherever I could. And at the same time I notice a lot of people expressing your sentiment. These systems make it easy(er) to model concepts in a mathematical way and this is my natural (or preferred?) mode of thinking. And they enable you to do it easily and ergonomically. What is there not to like? (I know there are flaws at hand, even some potentially very debilitating flaws depending on your use case. But damn, I'd use these languages wherever I can.)
- 4y ago
- AzzieElbab 4y agoI no longer think all kinds of gateways to Haskell is actually a good thing. Once you go through that gateway you are most likely to get frustrated and go right back, as evident from other replies. People say it's enforced purely functional programming is difficult to grasp but I write mostly pure FP in Scala and I get frustrated with how difficult it is to build something practical in Haskell
- rychco 4y agoI've seen Dhall mentioned on HN front page twice this past week. Is anyone here using it regularly? How has your experience been?
- pie_flavor 4y ago> Take Kotlin, for example. It has so many escape hatches that someone new to functional programming can end-up writing what is essentially an OOP/imperative style Java program, merely in Kotlin syntax. That's... literally the entire purpose of Kotlin.
- rkangel 4y agoIt is, and the author isn't criticising the language as a whole for it. They're merely commenting that it isn't a good options for forcing you to use and therefore learn functional paradigms.
- wolfspaw 4y agoI prefer the pragmaticality of Rust, or even it's father Ocaml, than the Over-the-top-abstractly Haskell.
- triyambakam 4y agoI was about to ask how you would describe OCaml as Rust's father, but I get what you mean actually.
- ebingdom 4y agoAlso the Rust compiler was originally written in OCaml. Not that that necessarily implies a parent-child relationship between the languages, but it's clear OCaml was on the minds of the original Rust developers.
- wrnr 4y agoBut what is Dhall? Ok yes, something that helps you write config files because Kubernetes is a pain. I am not a DevOps person so I can't always empathise with the problems DevOps deals with on a daily basis. That something is written in Haskell for Haskell sake is not something I care about. Not that I dislike Haskell, PostgREST is written in it and that is one of the coolest and most productive things I know about, and it does not ask me to learn Haskell (just a lot of SQL). How does it compare to something like CUE[1] which uses a lattice algebra to weave config files and code together to manage different configuration environments similar to how some computational-algebra-system use pattern matching and rewrite rules to encode mathematical knowledge. [1] https://cuelang.org/ https://cuelang.org/
- gregwebs 4y agoIMHO cue is generally better for complicated configurations, including Kubernetes. Dhall has some nice features though. In particular the ability to import other files as semantic hashes seems like a great feature. To manage configuration you also need a system to understand the state of the configured system so that when you delete a configuration you can reconcile that with the system. So then it becomes more practical to use Pulumi with TypeScript. It would be nice if there was a separate state reconciliation system that one could adapt to use with Cue or Dhall or any other frontend.
- cppforlife 4y agosince you mentioned Kubernetes... > It would be nice if there was a separate state reconciliation system that one could adapt to use with Cue or Dhall or any other frontend this exactly was thinking behind https://carvel.dev/kapp https://carvel.dev/kapp for Kubernetes (i'm one of the maintainers). it makes a point to not know how you decided to generate your Kubernetes config -- just takes it as input. > In particular the ability to import other files as semantic hashes seems like a great feature. it's an interesting feature but seems like it should be unnecessary given that config can be easily checked into git (your own and its dependencies).
- 4y ago
- flakiness 4y agoSkip the blog and look at the language landing page: https://dhall-lang.org/ https://dhall-lang.org/ The blog article talks too much but the language itself seems reasonable. Statically typed config languages sound like a neat idea to pursue, although I'm not sure how promising this particular one is.
- aidenn0 4y agoCame here to say that Dhall has the best landing page of any of these new config languages that are bouncing around lately.
- etra0 4y agoI recently tried to get into Haskell, while also looking for relevant projects written in it on Github and couldn't find anything "interesting" (this may vary from person to person, obviously). I was watching a YouTube playlist but I'd rather read something like "Haskell by example", or some sort of small apps with comments to understand how it works. I was interested in writing some binary parser in it but I failed miserably.
- picozeta 4y agoActually writing a self-contained parser (in essence a function parse :: [Binary] -> AST) is one of the things where Haskell shines. You could use `attoparsec` (and to start off, even using the stdlib's https://hackage.haskell.org/package/parsers-0.12.11/docs/Text-Parser-Combinators.html https://hackage.haskell.org/package/parsers-0.12.11/docs/Tex... can get you very far). And I say that as someone, whose top-rated comment in this thread is more or less a Haskell rant.
- xwowsersx 4y agoI think OP's point was that THEY failed miserably. Presumably, they reached for Haskell to begin with because they knew it's supposed to shine for things like writing parsers. Maybe they were making a point about learning curve or FUX with Haskell...not sure since OP didn't elaborate.
- etra0 4y agoThat's cool to know, maybe I should keep trying. And regarding your top comment, I agree that's quite hard to find interesting SW written in it, that's one of the reasons I quickly gave up, but I guess it doesn't hurt to learn about FP after all, I want to at least write something that works before finally decide if it's worth it or not.
- agentultra 4y agoI’ve been thinking about producing a video series giving an introduction to FP from the ground up. However I do stream myself working on non-trivial Haskell projects from scratch to give folks an impression of what it’s like work in this language once you’re comfortable with it. I do enjoy taking digressions to answer questions too, so if interested check out https://twitch.tv/agentultra https://twitch.tv/agentultra
- spion 4y agoI love Dhall, but I think Optionals might not be a good fit for a configuration language, especially one that has to deal with Kubernetes A Dhall joke (those that write a lot of it will get it): Some foo walks into Some bar and asks the bartender, do you have Some beer? The bartender answers: We have None.
- yarg 4y agoOne nice thing that can be done with pure functional programming (not sure what - if any - languages or runtimes implement it) is the caching of the results of expensive calls. If there's any escape hatch to a method/function there's no guarantee that the result of f(q) will be a constant.
- alkonaut 4y agoOn escape hatches: being able to do imperative style processing is great. A loop-and-mutation is often a much more readable way to write what could be written as a fold or (worse) some tail recursive method. F# does this very well I think, with imperative code sitting quite naturally inside an ML dialect. More importantly, it allows describing the how (or at least something more closer resembling the how) of the computation rather than just describing what is being calculated.
- ozmaverick72 4y agoAre Stack / Cabal written in Haskell ? If so I dont think thats a very good advert for the benefits of writing software in Haskell - the quality as an uninformed user would appear on par with a crappy Perl script.
- labrador 4y agoWritten by and for academics and/or others who don't have to ship software it seems
- ParetoOptimal 4y agoWhat experience(s) lead you to that conclusion?
- formerkrogemp 4y agoTalk to your kids about Haskell. Before someone else gets to them first. Please consult your resident programmer before trying Haskell. Overuse of Haskell could result in carpel tunnel, tunnel vision, monad pedantry, etc. http://www.willamette.edu/~fruehr/haskell/evolution.html http://www.willamette.edu/~fruehr/haskell/evolution.html
- DeathArrow 4y ago>Learning Haskell directly can be a very frustrating experience for all, but the most headstrong. Trying to directly introduce Haskell to a large team is almost guaranteed to fail. >However, there are a few languages, heavily inspired by Haskell, that have a much gentler learning curve. There are also functional programming languages which are not inspired by Haskell and which are easy to learn. I quite enjoy F# and was able to pick it up relatively fast. Also, about Haskell being hard, it still doesn't seem "rust" hard.
- olodus 4y agoAfter working with Kubernetes and Helm I have learned to hate mustache-style templating and be generally in-easy when working with yaml in general (though yaml Because of this I've started using Dhall in personal projects. It feels like the slimmed down functional thing you want with useful features you want when writing configs for example. I could even see it useful in other templating situations as well, which I am experimenting with but don't know for sure yet.
- ilvez 4y agoThanks for this comment. I'm currently introducing K8 at my company and thought about using Helm at first, but since I don't have too many services at this point, I fell back to standard yaml config. This confirms my choice for now. I'll look into Dhall instead. I skipped Helm since I felt it introduced too much new tooling on top of K8 which is also new in company and me. But then I also felt the issue of duplication quite immediately.
- chrisjharris 4y agoDhall is in some ways actually harder (at least, stricter) than Haskell, I think. The fact that there's guaranteed completion means the code has to have complete integrity. If you've defined a union type, then anytime you define a polymorphic function that takes that union type as an argument, you need to both handle all of the union type's actual types, and handle them properly. So even if you as the developer know that that one of the types is never going to actually be passed to this function, you can't just throw an error or set that scenario as undefined.