Live data from Hacker News

Show HN: I built a poker site with Haskell

github.com

81–90 of 121 posts

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

#81
post #78

Earlier quoted context omitted.

The nice thing about Haskell from a readability standpoint is to unpack what code does at any point, you only have to perform substitution (i.e. beta reduction) over and over. This is a key difference from most other programming languages, which require you to have a little VM in your head. "Localized reasoning" is what Haskellers call this. To read it quickly, you do have to learn & internalize abstractions. Both a…

You mean that decomposing abstractions with substitution works better in Haskell than in a lot of the other languages because programs in Haskell are essentially (pure) functions and abstractions are built by composing functions?

Yeah - referential transparency is what allows it to Just Be Substitution.

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

#82
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…

One problem is very generic tooling in Haskell. In many languages, you'll have a library that might provide a function like "iteratePokerGameStep." In the haskell community, the author is more likely to realize that this could just be implemented via "BiApplicativeProfuctorCategory.map." So instead of writing a 6 line "iteratePokerGameStep" which gets its own name, you're more likely to see someone just call "map." Much simpler code in some ways, much less simple in others.

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

#83
post #49

Earlier quoted context omitted.

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

> is not a difficult language to learn People say this about every single programming language.

Some have genuinely uniquely confusing bits. Like `this` in javascript. Or `Hold` and `Evaluate` in mathematica.

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

#84

Dumb question. Is Haskell ever the best tool for the job? I feel that every language has a sweet spot, but Haskell seems to be a language that people use just to show that they can . I've always wanted to learn, but I don't want to learn if there isn't a reason to.

Here's a popular "State of the Haskell ecosystem" page:

https://github.com/Gabriel439/post-rfc/blob/master/sotu.md

There are a number of things where haskell is best in class and a larger number of things where it's immature. The language itself could be excellent at far far more than it is today, but libraries are limited for many tasks.

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

#85
post #8

Earlier quoted context omitted.

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" a…

On the other hand, Haskell's strength is its abstraction power. Elm intentionally lacks (some of) that punch, as do a lot of other languages.

But since Elm is a DSL it can afford to cap the abstraction somewhere whereas Haskell is perhaps built for more complex problems than just a client facing web UI.

Having learned both, I feel the abstraction level is capped too low on Elm, sadly.

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

#86

Earlier quoted context omitted.

Ouch. That function is actually written in a pretty convoluted and redundant way. getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = do maybeEnvPort >= readMaybe That's starting to border on over-terse, so you could expand the bind operator into do notation if you wanted to spread it out a bit further. On the other hand, it's also starting to feel over-verbose, using do notation for only a single IO act…

In your first version, I think I would use = http://www.haskellforall.com/2015/09/how-to-make-your-haskel... getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = do maybeEnvPort Keeping the pattern match instead of using "fromMaybe" wouldn't be a bad idea, either: getSocketAPIPort :: Int -> IO Int getSocketAPIPort defaultPort = do maybeEnvPort defaultPort Just port -> port) It makes the default value stan…

For my part, for that logic I'd consider MaybeT. I don't like that a malformed environment variable gets the same treatment as a missing environment variable, though.

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

#87
post #75

Earlier quoted context omitted.

This is a bit clearer: def getSocketAPIPort(defaultport): return int(os.getenv('socketPort', defaultport))

Closer, but int can throw a ValueError. The original Haskell code defaulted to the defaultPort if the specified port could not be cast to an int.

I see. Though I think it's better to throw an error. I wouldn't want my app just coming up on default port if I had configured it incorrectly.

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

#88
post #42
post #31

Earlier quoted context omitted.

I feel like I'm in a unique place of learning Haskell, so I'll try to translate the last line of your first function: return . fromMaybe defaultPort $ maybeEnvPort >>= readMaybe Basically this is composing a function out of "return" and "fromMaybe" (using the composition operator "."), then partially applying defaultPort to that composed function, so you now have a function that takes one argument. The resulting func…

i like it, for some reason my brain dislikes switching from left/right a lot, so that's why i often avoid the $ operator, so instead I'd write: return . fromMaybe defaultPort (maybeEnvPort >>= readMaybe)

"Have the data flow in one direction" is a good rule of thumb in writing clear Haskell code.

That said, your conversion away from $ changes the meaning here (in a way that doesn't typecheck, I think - remember that regular function application binds tightest whereas dollar binds loosest) and you still don't achieve your goal.

Instead, maybe

   return . fromMaybe defaultPort $ readMaybe =
or even

   return $ fromMaybe defaultPort $ readMaybe =
If you still don't like the dollar signs, we can parenthesize instead in two correct ways, although I don't find them more readable:

    (return . fromMaybe defaultPort) (readMaybe =

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

#89

Earlier quoted context omitted.

Emacs works very well. Haskell is the second best emacs experience I've ever had, second only to Lisp. Things were not always this way. Just a few years ago, it was a bad experience, so if you have bad memories, it may be time to try again.

I used Haskell on Emacs a few weeks ago and there still seems to be some issues with regards indentation.

Ouch, it has been so long that I have forgot about this. Add this to your emacs init script somewhere:

    (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
It is also not compatible with older versions of intero and haskell-mode, so if you have old configuration there, you may want to remove it.

Honestly, it's even weird this isn't on by default.

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

#90

Earlier quoted context omitted.

I used Haskell on Emacs a few weeks ago and there still seems to be some issues with regards indentation.

Ouch, it has been so long that I have forgot about this. Add this to your emacs init script somewhere: (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation) It is also not compatible with older versions of intero and haskell-mode, so if you have old configuration there, you may want to remove it. Honestly, it's even weird this isn't on by default.

Thanks!
Post reply on HN