News for hackers. Stuff that matters.
Re:What I Wish I Knew When Learning Haskell by Apollidore on Saturday April 11, 2020 @06:35AM (#22840939)
Haskell is fun, but bear in mind that it's followes a purely functional programming paradigm, meaning you either do things the Haskell or you don't do them :). But it's a fun language to learn, and there are lots of free quality ressources on the internet
Re:What I Wish I Knew When Learning Haskell by marceloabsousa on Saturday April 11, 2020 @07:04AM (#22841039)
What do you mean by "either do things the Haskell (way) or you don't do them"? Isn't that the same with every language? I still don't understand why people put all sorts of unfair labels on Haskell. By labelling Haskell with "fun", we almost make it sound like it can't be used in production.
Re:What I Wish I Knew When Learning Haskell by Drakim on Saturday April 11, 2020 @07:43AM (#22841146)
What I think he meant is more like "either do things the functional Haskell way or you don't do them", as in, there is no non-functional fallback or alternative in the language, which some functional languages have.
Re:What I Wish I Knew When Learning Haskell by kadoban on Saturday April 11, 2020 @10:17AM (#22841790)
There's escape hatches here and there. If you need imperative code, use IO or ST. If you need to debug output something, Debug.Trace.

If you need to temporarily bypass purity there's unsafePerformIO and friends (or they can occasionally be used permanently if you do a lot of analysis I believe).

It's a pretty practical language compared to its reputation.

Re:What I Wish I Knew When Learning Haskell by Koshkin on Saturday April 11, 2020 @03:16PM (#22843505)
Actually, someone said, “Haskell is the world’s best imperative programming language.”
Re:What I Wish I Knew When Learning Haskell by sullyj3 on Sunday April 12, 2020 @10:24AM (#22848426)
Somebody said it, but it's glib, and not particularly true. I believe it was a comment on do notation, the bind operation, and programmable semicolons. The customizability is definitely cool, but nobody could possibly argue that imperative programming in Haskell is ergonomic.
Re:What I Wish I Knew When Learning Haskell by sullyj3 on Sunday April 12, 2020 @10:21AM (#22848408)
Sure, IO and ST are escape hatches, but they're not escape hatches that beginners struggling with the concept of a higher order function are going to be able to use.
Re:What I Wish I Knew When Learning Haskell by giantDinosaur on Saturday April 11, 2020 @07:46AM (#22841154)
I imagined it was more in the sense of the 'Have fun implementing Quicksort!' variety, where you're fighting the language constructs, basically, to do what you want.
Re:What I Wish I Knew When Learning Haskell by tmountain on Saturday April 11, 2020 @08:10AM (#22841241)
Haskell has a huge catalog of libraries you can reach for, so you don’t have to reinvent the wheel. That said, the Haskell way can seem very different than what you see in most languages. As an example, IO—or anything causing a side effect—has to happen in the IO Monad. There are good reasons for this, but it takes some getting used to.
Re:What I Wish I Knew When Learning Haskell by amelius on Saturday April 11, 2020 @09:09AM (#22841484)
But let's say I want to print something in a deeply nested function which isn't of the return-IO-Monad-type. Now I have to convert the entire call-chain of functions into Monad style. Is there some tool to do this automatically?
Re:What I Wish I Knew When Learning Haskell by kadoban on Saturday April 11, 2020 @10:06AM (#22841735)
For debug there is Debug.Trace which is about perfect.

For non-debug, you may be overestimating how useful it is to output from pure functions in production.

In general when you are in a situation where you need to change the Monad you're under, there's techniques and libraries for that (one way you define it once, give it a name, etc.).

The biggest pain tends to be going from pure to monadic in the first place, which last I used Haskell there wasn't much for but to just do it. There may be more tooling now, haven't seen.

Re:What I Wish I Knew When Learning Haskell by hopia on Saturday April 11, 2020 @10:13AM (#22841765)
Why would you want to print inside a pure function though?
Re:What I Wish I Knew When Learning Haskell by AnimalMuppet on Saturday April 11, 2020 @04:14PM (#22843894)
Because some non-technical manager came to you and said, "Can't you just print out the value here? And can I get it in the next 15 minutes?" and it was pretty clear that "No" was not an acceptable answer.
Re:What I Wish I Knew When Learning Haskell by vkou on Saturday April 11, 2020 @08:22AM (#22841278)
The parent poster is not lamenting that Haskell lacks a trivial sorting function.

They are lamenting that implementing a trivial sorting function in Haskell is difficult.

Re:What I Wish I Knew When Learning Haskell by kadoban on Saturday April 11, 2020 @10:09AM (#22841746)
Different things are hard or easy in Haskell compared to other languages. Mergesort would be the first one I'd reach for in Haskell if I'm implementing from scratch.

Quicksort isn't really hard, you just do it in IO and it looks about like what you'd see in any imperative language. (or you can use ST, but then you have to know about ST).

Re:What I Wish I Knew When Learning Haskell by tmountain on Saturday April 11, 2020 @09:02AM (#22841458)
I disagree.

  quicksort [] = []  
  quicksort (x:xs) =   
      let smallerSorted = quicksort [a | a <- xs, a <= x]  
          biggerSorted = quicksort [a | a <- xs, a > x]  
      in  smallerSorted ++ [x] ++ biggerSorted
Re:What I Wish I Knew When Learning Haskell by edflsafoiewq on Saturday April 11, 2020 @09:33AM (#22841581)
That is (infamously) not quicksort.
Re:What I Wish I Knew When Learning Haskell by remcob on Saturday April 11, 2020 @11:24AM (#22842131)
What's wrong with it?
Re:What I Wish I Knew When Learning Haskell by tossup8536 on Saturday April 11, 2020 @01:02PM (#22842665)
Performance. Internal representation. You are not actually modifying things in place. Those are the equivalent of linked lists not arrays. That quicksort is not quick at all because the append operation in Haskell is linear. You can't use those lists to implement quicksort.
Re:What I Wish I Knew When Learning Haskell by lonelappde on Saturday April 11, 2020 @02:25PM (#22843194)
Haskell is lazy. a ++ b === (head a) : ((tail a) ++ b) (plus the base case)

It is only linear when you force it to evaluate, which ideally happens only once (amortized) in your program when the result is consumed. As long as you are careful, you don't get the bad quadratic performance that you'd get from something like eagerly appending a character to a string in a loop in Java. There are either gotchas, though, including relying on the compiler to do things in constant space that naively look linear, and also knowing when the compiler won't help you and you have to structure your computation manually.

Re:What I Wish I Knew When Learning Haskell by Koshkin on Saturday April 11, 2020 @03:25PM (#22843561)
“Modifying things in place” is, from the logical standpoint, an unnatural and even dangerous thing. A person that is not familiar with (imperative) programming often has a hard time understanding variables and assignments (similar to some programmers not understanding pointers). Mathematics doesn’t have assignments, either. That should tell you something...
Re:What I Wish I Knew When Learning Haskell by vkou on Sunday April 12, 2020 @12:43AM (#22846112)
It mostly tells me that mathematics does not care about runtime or space performance. Which is fine, because mathematics is about solving abstract problems, not getting a Turing machine to solve concrete problems.
Re:What I Wish I Knew When Learning Haskell by recursive on Saturday April 11, 2020 @04:08PM (#22843846)
In that case, quicksort requires danger and artifice. In any case, it's not quicksort.
Re:What I Wish I Knew When Learning Haskell by CyberDildonics on Saturday April 11, 2020 @10:22AM (#22841820)
Won't this have to iterate through linked lists and create multiple new heap allocations on each recursive step? Doesn't that imply n log n heap allocations just to sort a list?
Re:What I Wish I Knew When Learning Haskell by remcob on Saturday April 11, 2020 @11:29AM (#22842165)
Yes, but due to lazy-evaluation that won't happen until you do something with the sorted list. Your performance may just blow up in some seemingly unrelated place.

My biggest problem with Haskell is how GC and lazy-evaluation makes it very difficult to reason about what the hardware is actually doing at a given point. I know there ways to inspect and control it, but I've found myself preferring languages that have simpler mental models.

Re:What I Wish I Knew When Learning Haskell by CyberDildonics on Monday April 13, 2020 @10:46PM (#22862281)
Right, by the time you have to control it, you are washing away all the advantages for using it.
Re:What I Wish I Knew When Learning Haskell by magicalhippo on Saturday April 11, 2020 @09:16AM (#22841508)
Not that I know any Haskell, but wouldn't smallerSorted already include x due to <= operator?

edit: also, how is the pivot element selected there?

Re:What I Wish I Knew When Learning Haskell by zests on Saturday April 11, 2020 @09:41AM (#22841610)
Both of your questions have the same answer. (x:xs) means x is the first element and xs is the rest.
Re:What I Wish I Knew When Learning Haskell by magicalhippo on Saturday April 11, 2020 @11:01AM (#22841998)
Aha! Thanks.

Obviously picking first element as pivot makes for a very poor Quicksort. Though I presume a better approach, say median of first, mid and last elements, would add but an extra line?

Re:What I Wish I Knew When Learning Haskell by sullyj3 on Sunday April 12, 2020 @10:31AM (#22848475)
The reason the first element is used as the pivot is that these are linked lists, not arrays, so it would take linear time to access the middle and end. This isn't a real quicksort.
Re:What I Wish I Knew When Learning Haskell by marceloabsousa on Saturday April 11, 2020 @09:50AM (#22841656)
Spot on. There's a lot of wisdom in this comment.
Re:What I Wish I Knew When Learning Haskell by CyberDildonics on Saturday April 11, 2020 @10:16AM (#22841785)
But you do have to invent something or you wouldn't be writing a program in the first place.

As soon as you need to control the order of execution, memory usage, IO, or any combination of those, you are fighting the language and into territory of things you can technically do and out of the realm of things the language makes easy.

Re:What I Wish I Knew When Learning Haskell by lonelappde on Saturday April 11, 2020 @08:49AM (#22841397)
For 99% of programmers, Haskell can't be used in production.
Re:What I Wish I Knew When Learning Haskell by yakshaving_jgt on Saturday April 11, 2020 @12:03PM (#22842340)
This is nonsense.
Re:What I Wish I Knew When Learning Haskell by gtycomb on Saturday April 11, 2020 @01:48PM (#22842969)
I wish I could give you a thumbs up for speaking plain truth here. Anyway programmers will find out for themselves how best to satisfy their customer need.
Re:What I Wish I Knew When Learning Haskell by masklinn on Saturday April 11, 2020 @07:17AM (#22841077)
> it's followes a purely functional programming paradigm

I'd say that it's one take on that paradigm, the Way of Monads is not the only way to do purely functional, Clean uses uniqueness typing instead. Though it otherwise has rather similar properties to Haskell.

Re:What I Wish I Knew When Learning Haskell by yeshengm on Saturday April 11, 2020 @08:00AM (#22841204)
I'd say start with some eager functional language such as OCaml without the "object" part. Haskell code is hard to debug cuz you can't rely on good old print.

Monad itself is never a silver bullet. Type systems and Composability are the true power of FP IMO.

Re:What I Wish I Knew When Learning Haskell by willtim on Saturday April 11, 2020 @08:11AM (#22841244)
Debugging declarative code is always hard, whatever the language. Haskell does allow you to use trace expressions which will output values to standard out, see Debug.Trace.

This is no reason to avoid arguably the most popular (and state-of-the-art) function language and implementation out there.

Re:What I Wish I Knew When Learning Haskell by bontaq on Saturday April 11, 2020 @09:15AM (#22841501)
It took me way too long to come across Trace, if it was more widely known I don't think we'd see so many "impossible to debug" related issues. It's great.
Re:What I Wish I Knew When Learning Haskell by marceloabsousa on Saturday April 11, 2020 @08:34AM (#22841327)
I think we can all agree that debugging languages with lazy evaluation is specially hard. To effectively use Debug.Trace you actually need to add strictness and that can be fundamentally incompatible if you do intend to use the full power of lazy evaluation.
Re:What I Wish I Knew When Learning Haskell by lonelappde on Saturday April 11, 2020 @08:51AM (#22841409)
Debug.Trace won't solve the space leaks lurking around every corner of your program, and won't shave the hundreds of megabytes to gigabytes of RAM the compiler needs for compiling a non trivial program with dependencies.
Re:What I Wish I Knew When Learning Haskell by hopia on Saturday April 11, 2020 @10:16AM (#22841786)
It's for runtime debug logging after all, not intended to solve those issues.

Space leaks I'd like to read more about but writings about them are a bit hard to come by. Recommendations?

Re:What I Wish I Knew When Learning Haskell by fulafel on Saturday April 11, 2020 @07:48AM (#22841161)
Though The Haskell Way includes the io monad, which is imperative code in practice :)