Live data from Hacker News

Show HN: I built a poker site with Haskell

github.com

1–10 of 121 posts

Re: Show HN: I built a poker site with Haskell

#2
So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like every expression implements 20 different things at the same time, which makes it really hard to decode what is going on.

Is it just me, or is this typical for all non-trivial Haskell code? I don't have any problems interpreting e.g. Clojure, or Javascript written in a functional style for that matter, but Haskell...

Re: Show HN: I built a poker site with Haskell

#4
Very awesome-looking project! I think this is the kind of thing that Haskell needs more of: networked application code that is tangible and can give more curious folks (like me) an idea of how this language might be useful for our own projects.

Edit: only thing missing is PureScript on the frontend ;)

Re: Show HN: I built a poker site with Haskell

#5
post #2

So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like…

I think part of the problem is that Haskell code can be very terse. When reading Python I expect to be able to easily understand what's going on in a 5 line function because the pythonic style limits what you can do in 5 lines. But in haskell a 5 line function can be pretty sophisticated.

Re: Show HN: I built a poker site with Haskell

#6
post #2

So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like…

Haskell is not a difficult language to learn, but unlike imperative languages, you can't just start reading the code if you "know literally nothing about Haskell". One thing to keep in mind is that every other line in Haskell is basically just composing functions together, but you need to know how all those weird >>= and and effect code/composition flow

Re: Show HN: I built a poker site with Haskell

#7
post #3

Very neat! I've been working on a network application in Haskell too; this is a great reference. Is this project still active? Are there some features you'd like help developing?

Yes this project is active. That would be awesome if you contributed. There are a lot of features to add. Would you like me to add some of these to the issues on Github? Feel free to add your own suggestions to the issues as well.

Re: Show HN: I built a poker site with Haskell

#8
post #2

So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like…

Haskell is dense. I'm picking it up now[0], so this project was very useful for me to see how some "real world" Haskell is written. But yes, take for example this function

  getSocketAPIPort :: Int -> IO Int
  getSocketAPIPort defaultPort = do
    maybeEnvPort  return defaultPort
      Just port -> maybe (return defaultPort) return (readMaybe port)
It gets a port from an environment variable, if it can, otherwise a default port. Conceptually, this is easy to understand, but translating your understanding of that process to Haskell is not 1 to 1. For example, the last line alone:

  Just port -> maybe (return defaultPort) return (readMaybe port)
You have to understand Maybe (and failure contexts), you have to understand that "return" does not return from a function like typical imperative languages, instead it wraps a type in a Monad (in this case, the IO Monad), and you also have to understand that most of those things on that line, including the "return" function, are parameters to the "maybe" function.

There's a lot to understand in terms of the underlying machinery of Haskell to be able to read its cryptic flow and syntax. But it is worth it imo.

0. http://learnyouahaskell.com

Re: Show HN: I built a poker site with Haskell

#9
post #2

So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like…

It's not a good idea to try reading Haskell by "brute force", trying to figure it out as you go.

I suggest you first read through something that teaches you the basics like "Learn You a Haskell" or similar.

In a way, the experience is more like Clojure than Javascript. If you've read a Java-like language before, figuring another one tends to be easy. But if you've never read a Lisp-like, all the Java-like experience in the world won't help you to read a non-trivial Lisp program. You will just see some weird parentheses and won't be able to make head or tails of it.

Haskell is similar. Some upfront learning is needed before reading non-trivial programs.

Re: Show HN: I built a poker site with Haskell

#10
post #8
post #2

So, I know literally nothing about Haskell, and I would rate my knowledge of functional programming theory as 'beginner' at best, but I still get baffled every time when reading Haskell code that implements anything other than something trivial like a fibonacci sequence. The poker server code looks extremely tidy and well engineered, so that can't be the problem, but to me it's utterly incomprehensible. It seems like…

Haskell is dense. I'm picking it up now[0], so this project was very useful for me to see how some "real world" Haskell is written. But yes, take for example this function getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = do maybeEnvPort return defaultPort Just port -> maybe (return defaultPort) return (readMaybe port) It gets a port from an environment variable, if it can, otherwise a default port. Co…

Though notice that you picked literally the most trivial example in the entire codebase that anyone can understand without explanation.

Elm is onto something with its obsession with simplicity and lack of features. I go back to old Haskell code and have to completely recredentialize in Haskell before I remember what's going on. I return to old Elm code and need very little ramp up.

I'm not making an "Elm > Haskell" argument, I just think experimentation with simplicity does this family of languages a favor.

Post reply on HN