top | item 12782888

A Taste of Haskell

157 points| def- | 9 years ago |hookrace.net | reply

116 comments

order
[+] agentgt|9 years ago|reply
As for the Java bashing in the beginning I'm not saying Java is anywhere near the expressive power of Haskell but many people think different things based on Java because of features they either don't know about, outdated libraries used, or experiences with older versions and codebases.

For example most don't know that Java actually does have macro like capabilities through APT (annotation processor that will work automagically I might add). Some might say ewww its not macros but then again annotation processing might just be 80/20 good enough (aka what OCaml learned with ppx vs camlp) and that Java now sort of has traits and that its code swapping is actually fairly good (jrebel). There are even sadly people that don't know Java has lambdas, and even some (usually C++ dudes) that don't know it has generics. Most don't even know that you can combine interfaces with generic types as in: `<T extends Comparable & Serializable> void someFunc(T t)`.

Yes Java is not Rust, Haskell or even OCaml in expressiveness but it certainly is more powerful than Golang and definitely compiles fast (albeit starts up slow).

That being said OCaml is still my favorite. Compiles fast and easier for me to understand. Super mature and lots of companies use it.

[+] iLemming|9 years ago|reply
It's not Java what makes Java platform one of the most popular but rather JVM. That's why Clojure grows in popularity. Because it brings the expressiveness.
[+] acchow|9 years ago|reply
> and lots of companies use it

Curious, who uses ocaml other than FB and Jane Street?

[+] sa1|9 years ago|reply
That's not really the Sieve of Eratosthenes. The list data structure is not well suited for the algorithm. See [1] for a proper discussion. As someone who wants to write Haskell(and loves it) for code with mathematically well defined guarantees, the propagation of such examples, where the guarantees or behavior is not clear to the author, is not helpful.

[1]: https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf

[+] pera|9 years ago|reply
It's the same example displayed in haskell.org though.
[+] TheAceOfHearts|9 years ago|reply
I got started with Haskell recently, and I'm really regretting not having picked it up earlier. Most of what I knew about types came from C, C++, or Java; so it's a big leap.

I've been using Haskell for Mac IDE [0] while experimenting, and it's been great fun.

The thing that prompted me to give Haskell a a try was this video [1] of a guy using Haskell to generate Elm types, in order to maintain consistent types across the stack. This idea captivated my interests. I'm confident that GraphQL and Relay, or something along those lines, is gonna be the future.

My experience so far has been that Elixir feels more welcoming and beginner friendly. There's nothing wrong with the Haskell community (or my limited interactions with it so far), but so far it's just felt a bit drier.

[0] http://haskellformac.com/

[1] https://www.youtube.com/watch?v=sh4H8yzXnvw

[+] Matachines|9 years ago|reply
Of course Elixir is more welcoming—the language is "practically" functional, easy, and made for building stuff. Haskell's purity and academic background is definitely a big impact on its culture.
[+] acchow|9 years ago|reply
If you delve deep enough into C++ TMP, it's just as expressive (more expressive in some ways) as Haskell. You can actually do dependent types in C++.
[+] Dzugaru|9 years ago|reply
Don't know about Haskell, but what really got me (a long time CSharp programmer) into functional programming was this awesome site [1] (and a man behind it with his awesome talks) - which is focused on core aspects of FP (applicable in most languages nowadays) in real-world applications.

[1] https://fsharpforfunandprofit.com/

[+] shados|9 years ago|reply
I love that site. The best part about it is that it gives you all of the common names for stuff like category theory concepts. Eg: the various ways map, flatMap, bind, etc are called across languages.

Because its a pain in the ass to learn those concepts from scratch when you're looking at code in one language but reading a tutorial in another...the concepts are language agnostic, the naming conventions however are not.

[+] androidfox|9 years ago|reply
Nice link. One related question : where have you used Haskell in real life. Do some top companies use Haskell to solve problems
[+] samcal|9 years ago|reply
Yes, but only recently. The most notable example in a top company is Facebook's spam detection service, powered by their library called Haxl[0]. The language allows some very skilled programmers to build this library that makes it very easy to write spam rules. Lower-level engineers can then write very simple and elegant code that looks sequential but is automatically parallelized by the library.

The service is a big deal, because every action or request that anyone makes on Facebook touches this service.

[0]: https://code.facebook.com/posts/302060973291128/open-sourcin...

[+] tikhonj|9 years ago|reply
I'm currently using Haskell to do supply chain optimization at Target. It's pretty awesome! The language lets us express our models in ways that feel natural.

We're both solving some specific problems (ie inventory control, network/transport optimization) and building a pretty general framework for expressing, analyzing and solving large stochastic optimization problems. Haskell is a great fit because it's extremely expressive and lets us write and reason about our problems in a natural, expressive way. It helps that we have a very mathy team in a mathy field :).

Our team also has a bunch of people with programming language research backgrounds, and our long-term remit is to apply programming language ideas to operations research. Turns out that—for a whole class of PL problems and PL people—Haskell is the perfect language :).

I also know people use Haskell at Facebook (already mentioned), Google (Ganeti and some unnamed X project), a few banks (JP Morgan, Barclays and Standard Chartered) as well as a whole bunch of startups and small companies.

[+] pea|9 years ago|reply
We're a startup in London (shameless plug: www.nstack.com) using Haskell to develop a containerised microservices platform, bringing in lots of low-level Linux coding along with high-level concepts such as typed DSLs.

So far it's working extremely well for us and has been a great decision - letting us build complex/reliable systems really quickly and effectively. It is also very good for attracting amazing people, and we have found a small Haskell team can deliver truly spectacular product. This does on how you architect a Haskell codebase: e.g. you could spend a ton of time focusing on the most pure approach vs. pragmatism, so it's a balancing act.

[+] bertiewhykovich|9 years ago|reply
This question gets asked regularly, and every time Facebook's spam detection service, Standard Chartered's (never-seen) codebase, and maybe one or two other firms that no one's ever heard of get invoked. These are seemingly the only examples.
[+] sa1|9 years ago|reply
Standard Chartered has some 3 million lines of Haskell, but they don't use GHC, they have their own internal compiler.
[+] wuschel|9 years ago|reply
I second this question and would like to add another one:

Where is it that Haskell shines?

[+] eli_gottlieb|9 years ago|reply
Well, someone seems to show up to Boston Haskell every month having used it in industry, and I've used it for a paper on probabilistic modelling in my copious free time.
[+] mahyarm|9 years ago|reply
I really want to warn people from using long-to-compile languages in big projects. And by long, I mean longer than C++. From what I heard Haskell has compile time issues.

You will regret it once your in that position and it is hard to get out of once your there.

[+] joobus|9 years ago|reply
I've spent quite a bit of time with Haskell, and all the beginner text like this link are easy to grok, but where I've constantly come up short is trying to write an app with, for example, a configuration and a database connection. Having multiple levels of Monad transformers just confuses me and I never get anywhere useful. Something like:

App MaybeT IO (StateT IO (EitherT IO Text SomeRecord))

Or something. I haven't figured this out.

[+] spion|9 years ago|reply
Use IO for everything at the beginning. Use wai/warp to run an app directly and setup handlers. Use postgresql-simple to send queries. Read the settings object once, then pass it everywhere.

You can slowly start writing generic types for your pure code after a while. For example, replace types such as `[t]` with `Functor f => f t` if the only list-related operation done in that function is `map` (fmap). Try to take advantage of the stuff here: https://wiki.haskell.org/Typeclassopedia

After a while of doing this, you can start looking into how you can write your code in a way to have more generic types, then specialise it for the concrete problems you're solving

Finally at this point transformers should become easier and more obvious. Perhaps the first one would be to replace passing the config everywhere with ReaderT. Implementing a few transformers by yourself should help. Start with MaybeT and continue with ReaderT. Tip: `liftIO` magically works but you don't have to always understand how. Maybe also try free monads if transformers seem too annoying!

[+] joelthelion|9 years ago|reply
You shouldn't need this stuff if you don't want to use it. Just write a few IO functions for interaction with the real world, and pure functions for the rest. I made the same mistake in the past, and I was completely lost. I'm still nowhere near advanced, but sticking to simple stuff and learning slowly I am able to be quite productive now.
[+] tome|9 years ago|reply
> App MaybeT IO (StateT IO (EitherT IO Text SomeRecord))

Ouch! I've written Haskell commercially for the last four years and I've never written (or had to read) anything like this!

[+] cies|9 years ago|reply
There are some book recommendations at the bottom of the article, which are missing the (IMHO) latest-and-greatest introductory resource to Haskell: the book Haskell from First Principles.

http://haskellbook.com

[+] KennyCason|9 years ago|reply
I love Haskell, but if you hate Java, but still want to leverage the nice Java ecosystem, (libs, IntelliJ, JVM, tooling, etc) try Kotlin! :) https://kotlinlang.org/
[+] whateveracct|9 years ago|reply
If you love Haskell I guarantee you will not love Kotlin in the same way. Your best overall bet for Haskell-like FP on the JVM is Scala+cats/scalaz and other Typelevel-endorsed libraries. Unlike Kotlin, it gets pretty close.
[+] virtualwhys|9 years ago|reply
That would be an odd choice for a Haskell alternative. Lacking higher kinded types and type classes is a bit of a show stopper.

The obvious choice for Haskell on the JVM is Scala.

[+] mahyarm|9 years ago|reply
Does kotlin have the same compile time, binary size and IDE indexer choking issues as Swift? I've heard that it has similar problems. I would not use Kotlin for a large project if that is the case.
[+] kinkdr|9 years ago|reply
Started learning Haskell just a couple of weeks ago. My only complaint with the language so far is that I cannot have the same name for a field in two records in the same module.

Other than that it is amazing the confidence it gives me; if it compiles it works (r).

[+] krautsourced|9 years ago|reply
This may sound (and probably is) quite superficial, but I am immediately put off by any language that uses syntax like this: foldr' (+) :: Num t1 => t1 -> [t1] -> t1 Why? Because of things like => and -> are just a pain to write all the time and make you chase all over the keyboard, even more so on non-english keyboards. Just my very personal preference of course, but still...
[+] dancek|9 years ago|reply
It is quite superficial. Code being easy to read is much more important than code being easy to write. I'm not saying it's a bad idea to have both, but look at Java or C# that are a pain to write without a very smart IDE (just because of the amount of boilerplate). Even they have been saved by tooling.

Also, modern popular languages tend to use arrows (Java, C#, ES6). Not to say that popularity matters, but people are used to it nowadays.

[+] lifeisstillgood|9 years ago|reply
How bad is it looking at the examples and thinking "I love that lambda symbol as a prompt. I want"

I have to revisit my base setup soon. The 1990s wants its bash_profile back

[+] jjawssd|9 years ago|reply
How difficult is it in your experience for developers to learn Haskell while on the job?
[+] NotThe1Pct|9 years ago|reply
I tried haskell queues a while ago - under the advice of a friend and compared with a straightforward C++ queue - it was about 100x slower. Abandoned the idea.
[+] bbcbasic|9 years ago|reply
Let me guess ... you used [a]
[+] 59nadir|9 years ago|reply
You should do a write-up on it and show your tests. As it stands, this post has almost no real value for anyone else and no one knows anything about what you used and how.
[+] xamuel|9 years ago|reply
I taught myself Haskell because people say it improves you as a programmer. I didn't see that, but I have a math PhD so maybe I'm just too familiar with abstract types to gain new insight from Haskell.

As a language, it's sterile. You can tell it was designed by committee.