4 ms·
This would be a great place for any Haskell programmers to insert their own thoughts. I like the look of Haskell myself but I've spent more time with Rust becau
by julianeon 2y ago
This would be a great place for any Haskell programmers to insert their own thoughts. I like the look of Haskell myself but I've spent more time with Rust because it seems more practical.
- eru 2y agoIf you like another language that's a bit like Haskell-but-more-practical, give OCaml a try. They even have a for-loop in OCaml!
- habitue 2y agoThere's... forM_ in Haskell. that's basically a for loop, right?
- eru 2y agoYes, you can implement your own loops in Haskell and OCaml (and Scheme and even the GCC-variant of C). However, I meant specifically that OCaml is so 'pragmatic' that they have a for-loop as a built-in syntactic element in the language. They also have mutable variables built-in. In eg Haskell those are 'only' available as part of the standard library.
- habitue 2y agoSorry, bad attempt at humor. I knew what you meant, I was just poking fun at forM_ for being bizarre and unergonomic
- tome 2y agoWhat do you find bizarre and unergonomic about it?
- habitue 2y agoIf you're quite used to Haskell, it's nbd. If you're coming from another language with for loops and someone tells you it's a for loop, you might be surprised that you need to use $ and the loop variable comes after the sequence for x in range(10): print(x) forM_ [0..10] $ \x -> putStrLn x
- karmakurtisaani 2y agoI'm convinced the people who came up with Haskell syntax were on some sort of bath salts.
- nequo 2y agoThe reason it looks the way it does is that forM_ is just a function like any other, not a keyword in a dedicated syntactic construct.
- karmakurtisaani 2y agoYep, and then there's the $, \ and PutStrLn. As a non-Haskell programmer none of those mean anything to me.
- nequo 2y ago$ is short for “put everything to the right inside parentheses” and \x -> y defines an anonymous function. Why do you expect to understand the syntax of a language you never studied?
- karmakurtisaani 2y ago> $ is short for “put everything to the right inside parentheses” There's, you know, also the actual parentheses that everyone already knows. > Why do you expect to understand the syntax of a language you never studied? Because most languages have a syntax that you can grasp almost immediately, since they conform to a common syntax, rather than invent everything all over again. Then you can focus on the actual features of the language and are not bogged down by syntax.
- reduck 2y agoYour profile says > Emacs/Lisp forever I think of Haskell as the declarative statically typed lisp I’ve always wanted.
- danieltanfh95 2y agothen you've never really wanted a lisp...
- kccqzy 2y agoRust is indeed more practical than Haskell, I wouldn't deny that. But Rust lacks full support for higher-kinded types. Exploring a few type classes (known as traits in Rust) like Applicative, Foldable, Traversable can really open your mind. An exaggerated quip by Haskellers is that there are entire libraries on NPM that simply implement the single function `traverse`. While that's an exaggeration, it really helps to look at a few dozen things the single `traverse` function can do to realize its generality.
- eru 2y agoWell, we have entire libraries in Haskell that implement `traverse` for a specific data type, too. The nice thing in Haskell is that the language is strong enough that we can tell the compiler that all those disparate implementations have something in common.
- develop7 2y agoCould you elaborate on the "more practical" bit?
- julianeon 2y agoMore jobs I could get with it, more open source tools or projects I could work on with it.
- kccqzy 2y agoI just thought of one more thing. I really like -fdefer-type-errors in GHC and wish Rust has something similar. Both Rust and Haskell are very opinionated in the way the program is organized. Adding a seemingly small feature can often result in larger-than-expected refactoring. (In Haskell, one might need a new monad transformer layer or convert non-monadic code to monadic; in Rust one might have to rethink ownership patterns or add Rc to many places.) In GHC, type errors can be deferred until run time, until the point where the expression containing the type error is forced. If the expression containing the type error is never evaluated, the program works; if it is, you get an exception raised. This combines especially well with laziness: for example one can find the length of a list even though evaluating the element of the list would result in runtime exceptions. This is useful when I'm halfway through a large refactoring, when there are plenty of errors remaining, but I want to run my test suite to determine whether the parts without compiler errors actually pass their tests.
- mcguire 2y agoAs long as you remember to turn it off after you're finished refactoring. :-) (Yeah, I'm the guy with the co-worker who kept turning off -Wall in C++ because "nobody has time for that".)