3 ms·
Thanks for that code. I don't know anything about Haskell so I attempt a UX test: results is an array of Int, but do the double [[ ]] brackets mean something s
by pmontra 10y ago
Thanks for that code. I don't know anything about Haskell so I attempt a UX test:
results is an array of Int, but do the double [[ ]] brackets mean something special? I hope they do, otherwise why planting doubts in people's mind.
<- is assignment or pattern matching, probably the latter.
the $ after guard is... what? Maybe a noop like Python's :
Maybe
guard $ expression
something
is equivalent to
if expression
something
If this is the case, it's much less readable because people are left guessing. The lack of indentation doesn't help either.
u is probably the variable that's iterated over in where u = [1..26]
Not very readable to put that after every use of u. This is easier to read
where u = [1..26] do
which is many languages is
for u in [1..26] do
I can imagine that where is more general and is used in other contexts.
Don't take these as criticisms of Haskell, only as a UX test. Python's list comprehensions have never been very readable to me. This Haskell loop is somewhat better.
I'm sure there are good reason for designing Haskell's syntax like that. Programming languages belong to lineages and tend to perpetrate the syntax of their parents. It makes them easier to adopt to developers well versed in their parent languages but that could also make them difficult to grasp for developers of other language families. Maybe luring imperative developers into the functional world is not one of the goals of Haskell and Haskell has achieved its goals as it is.
Still I believe that the first functional language that looks like an imperative language will move many developers from OOP to functional. Elixir attempted that, consciously or not, but it's not enough. The barrier there are the OTP patterns, which are not easy to use properly. There are many different choices for writing a process (what in OOP would be an object with its own CPU) and its hard to chose the proper one. GenServer, Agent, Task? Nobody is asking these kind of questions in Ruby or Python https://groups.google.com/forum/#!topic/elixir-lang-talk/DCTXyGV791w https://groups.google.com/forum/#!topic/elixir-lang-talk/DCT...
There is also the code to add them to the supervision tree (the cool systemd-inside-the-language thing of Erlang and Elixir). I can't help thinking that Elixir has to be streamlined.
- yomly 10y agoIs [[Int]] a nested array of ints? This is because there could be more than one set of solutions to the simultaneous eqn
- hirsin 10y agoIn the same boat of not knowing Haskell, this is how I interpreted it - the [[]] denotes a nested array of ints, where each array represents a set of variable values on 0..26 that satisfy all guards. Guard $ foo Is equivalent to filtering out the values in u in each variable that fails foo. They're staged that way for the sake of performance - filter out possible values of x now so that the next guard statement has fewer possibilities to iterate over. Then, once all guard statements have been put into effect, the full set of combinations of values that pass each guard are placed in the array. Critically, it is not "for u in [0..26]" but "u=[0..26]", which gives me the idea that this isn't a loop but a filter.
- wz1000 10y ago>Not very readable to put that after every use of u. This is easier to read > where u = [1..26] do This isn't valid Haskell, but this is let u = [1..26] in do ... Also ($) is just sugar to avoid parenthesis. Instead of writing f (1+2*3) you can write f $ 1+2*3 Haskellers have a massive fetish for eliminating parenthesis, perhaps in order to avoid their code looking like lisp.
- gh02t 10y ago> <- is assignment or pattern matching, probably the latter. Neither really, though I guess it's kind of like assignment, but it's usually read "draw from". Do-notation is sugar for working with monadic values, which are kind of like containers that hold a value. It's a bit hard to explain, but basically it means to pull the enclosed value out of the container on the right hand side and reference it according to the name on the left hand side. > the $ after guard is... what? $ is function application. It basically means to evaluate the right hand side before passing the result to the left hand side. It's used to avoid parentheses, `f $ g h` is like `f (g h)` (Haskell doesn't use parenthesis for function evaluation). Haskell syntax is lovely when you're used to it, but it's also subtle. IMO it can be easy for people who aren't familiar to get the general idea of what's going on but the specifics are often not what you think.
- YeGoblynQueenne 10y ago>> Still I believe that the first functional language that looks like an imperative language will move many developers from OOP to functional. That's supposed to be the deal with javascript (but please don't ask me for a source; I was first introduced to the idea that js is functional in a book in an old workplace's library, where I was waiting for my boss to chew me up. Needless to say, I haven't used javascript much).