Live data from Hacker News

Snake in Elm with WebGL

github.com

21–29 of 29 posts

Re: Snake in Elm with WebGL

#21

Earlier quoted context omitted.

Redux follows the same pattern with your more "familiar" syntax. Typed functional programming offers wins that forces more safety and modularity onto the code. These are all long term wins. Ultimately I would argue that elm's syntax is better suited for extremely complex projects that have low tolerance for bugs.

Redux is a javascript library. It shares some idioms with correct Elm code, but is a very different beast.

Right but the underlying design pattern is the same. This is all I'm saying. Redux can almost be thought of as an Elm pattern implementation with "familiar" imperative syntax.

Re: Snake in Elm with WebGL

#22

Earlier quoted context omitted.

Currying

I can get the same effect as currying with C syntax by deliberating invoking a special function: functools.partial(old_function, my_new_argument) Is this such a useful thing that you need the functional style syntax to make it even easier to do?

Yes

Re: Snake in Elm with WebGL

#23

Earlier quoted context omitted.

Currying

I can get the same effect as currying with C syntax by deliberating invoking a special function: functools.partial(old_function, my_new_argument) Is this such a useful thing that you need the functional style syntax to make it even easier to do?

[deleted]

Re: Snake in Elm with WebGL

#24

Earlier quoted context omitted.

Currying

I can get the same effect as currying with C syntax by deliberating invoking a special function: functools.partial(old_function, my_new_argument) Is this such a useful thing that you need the functional style syntax to make it even easier to do?

You can do it in Python as you have, but it becomes second nature with Haskell (I can't speak to Elm directly). You might not even realize you're doing it.

Add 5 to each num in a list (using a pretend function called `add` in both languages to be fair):

  map(functools.partial(add, 5), nums)

  map (add 5) nums
Add 5 to each in a list of list of numbers:

  map(functools.partial(map, functools.partial(add, 5)), nums)

  map (map (add 5)) nums

Re: Snake in Elm with WebGL

#25
post #4

Bug: Create snake of length two. Move RIGHT. Quickly press UP LEFT in quick succession. Lose. Similar bug with RIGHT->DOWN->LEFT And so on for all the other initial directions.

Yeah happened to me too, thought it was my mistake but now I blame the bug :D

Re: Snake in Elm with WebGL

#26

Earlier quoted context omitted.

I can get the same effect as currying with C syntax by deliberating invoking a special function: functools.partial(old_function, my_new_argument) Is this such a useful thing that you need the functional style syntax to make it even easier to do?

You can do it in Python as you have, but it becomes second nature with Haskell (I can't speak to Elm directly). You might not even realize you're doing it. Add 5 to each num in a list (using a pretend function called `add` in both languages to be fair): map(functools.partial(add, 5), nums) map (add 5) nums Add 5 to each in a list of list of numbers: map(functools.partial(map, functools.partial(add, 5)), nums) map (ma…

I suppose it would make more sense to write these as lambdas in a c style syntax

   nums.map(|sublist| sublist.map(|num| add(num, 5))
Maybe I haven't done enough functional programming yet, but I still like the explicitness of the C-style over the functional style.

Re: Snake in Elm with WebGL

#27

Earlier quoted context omitted.

You can do it in Python as you have, but it becomes second nature with Haskell (I can't speak to Elm directly). You might not even realize you're doing it. Add 5 to each num in a list (using a pretend function called `add` in both languages to be fair): map(functools.partial(add, 5), nums) map (add 5) nums Add 5 to each in a list of list of numbers: map(functools.partial(map, functools.partial(add, 5)), nums) map (ma…

I suppose it would make more sense to write these as lambdas in a c style syntax nums.map(|sublist| sublist.map(|num| add(num, 5)) Maybe I haven't done enough functional programming yet, but I still like the explicitness of the C-style over the functional style.

Sorry, but there is nothing more explicit about using lambdas as you have done, it's simply redundant (notice the repetition of sublist and num arguments).

Re: Snake in Elm with WebGL

#28
post #9
post #4

Bug: Create snake of length two. Move RIGHT. Quickly press UP LEFT in quick succession. Lose. Similar bug with RIGHT->DOWN->LEFT And so on for all the other initial directions.

Not the author, but I've implemented my own snake game and this bug is fairly easy to kill. (1) - You can only change directions that will change your axis, if you're going left your possible changes are up and down, .... (2) - You should be only able to consume one direction change per game tick, what is happening here is that rule (1) is working but you can change into the other axis, and then back to the other axi…

Maybe it makes it too easy, but I would enjoy the mechanic that quickly pressing UP LEFT when moving right would make the snake head move one square up then turn left and continue left. I suppose that would require some special casing, and you wouldn't want to support longer queued direction changes. Maybe a nice implementation would be that for inputs queued within a single game tick, execute the first input for one square of movement, then the last input for the next tick.

Re: Snake in Elm with WebGL

#29
post #5

I attended a two day Elm workshop a while back. There is a lot there to love, I just think it's Haskell inspired syntax is a major impediment to it's mainstream adoption. I however would love to be proven wrong as the webs reliability would be so remarkably improved.

I work on Reason, which is something you might like: http://facebook.github.io/reason/ Elm has been personally an inspiration too. Nice set of decisions and tradeoffs for what they're trying to achieve, though yeah, mainstream syntax might not be one of them, but that's fine.

sorry, what are these decisions and tradeoffs? why not just use ocaml(for anyone who doesn't mind not C-like syntax)?
Post reply on HN