You are viewing a single thread.
View all comments
32 points

Before studying CS, I recognized it as ‘the bioware puzzle’. They were probably copying their own scribbles fron back then.

Haskell was the hardest, but it looked the most beautiful.

permalink
report
reply
34 points

Haskell was the hardest, but it looked the most beautiful.

That pretty much sums that language up

permalink
report
parent
reply
9 points

In order to write a haskell program, you must first write the corresponding haskell program.

permalink
report
parent
reply
3 points

And in order to do that, you have to imagine sisyphus happy

permalink
report
parent
reply
8 points

Strange. I find the language hideous, most likely because it resembles math, or maybe because I’m already used to the C-like syntax.

permalink
report
parent
reply
15 points

Haskell is beautiful because it resembles math

permalink
report
parent
reply
4 points

Functional programming flips your brain around backwards, but shader programming will turn it inside-out.

permalink
report
parent
reply
4 points

For more brain flipping try looking into hardware description languages (Verilog) or proof assistants (Coq).

permalink
report
parent
reply
10 points
hanoi :: Integer -> a -> a -> a -> [(a, a)]
hanoi 0 _ _ _ = []
hanoi n a b c = hanoi (n-1) a c b ++ [(a, b)] ++ hanoi (n-1) c b a

From here: https://www.rosettacode.org/wiki/Towers_of_Hanoi#Haskell

permalink
report
parent
reply
12 points
*

Edit: I understand it now. That first line is just a really weird way to define a function.

permalink
report
parent
reply
5 points

Welp, imma try myself at an explanation. Mostly cause I haven’t written Haskell in a while either.

So, that first line:

hanoi :: Integer -> a -> a -> a -> [(a, a)]

…actually only declares the function’s type.

In this case, it’s a function that takes an Integer and three values of a generic type a and then returns a list of tuples of those same as.
So, those as are just any types representing the towers. Could be strings, integers, custom data types, whatever. The returned tuples represent movements between towers.

Following that are actually two definitions of the function.

The first definition:

hanoi 0 _ _ _ = []

…is the recursion base case. Function definitions are applied, whenever they match, being evaluated top-to-bottom.

This line specifies that it only matches, if that first Integer is 0. It does not care what the remaining parameters are, so matches them with a wildcard _.
Well, and to the right side of the equals sign, you’ve got the return value for the base case, an empty list.

Then comes the more interesting line, the recursion step:

hanoi n a b c = hanoi (n-1) a c b ++ [(a, b)] ++ hanoi (n-1) c b a

This line matches for any remaining case. Those small letter names are again wildcards, but the matched value is placed into a variable with the provided name.

And then, well, it recursively calls itself, and those ++ are list concations. This line’s only real complexity is the usual Tower Of Hanoi algorithm.

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.3K

    Monthly active users

  • 1K

    Posts

  • 38K

    Comments