|
|
|
|
|
by bsznjyewgd
4036 days ago
|
|
>recursion and restricting all their programs to be a singular composite of expressions Simple effect-free loops in an imperative language translate directly to a recursive function, which is just a labeled loop that makes explicit what/how state is manipulated each loop iteration. (Edit: For effectful loops, it's common practice in imperative languages to interleave the effects with the program logic. (Un?)fortunately, Haskell discourages this practice and encourages you to refactor the pure parts of your program from the effectful parts. This might make your program more reusable and testable, but it's an obstacle if you are just writing a fancy Hello World and want to get stuff done.) The singular composite of expressions is not a necessity, but to avoid it you have to give names to all your intermediate states, whereas a typical imperative language reuses the same name repeatedly. |
|
No more than imperative languages do. Speaking from experience, if you wanna slap IO on the arse of all your types, no one can stop you. Our friggin' project/dependency management tool is written like this. Yes, Haskellers usually prefer something nicer but nobody's going to steal your compiler if you don't.
We should avoid mistaking our discomfort with a language or idiom with what it does or does not encourage, can or cannot do. Chopin's nocturne op 48 1 is not difficult because pianos discourage it, it's difficult because it's difficult. In fact, it would be extremely hard to translate to a less expressive instrument. Similarly, writing programs in a well-factored design that separate actions from the computations that decide what happens from the datatypes that model them takes effort and practice, whether you use Haskell or not. I would submit that using a less expressive language will not make the task itself easier any more than trying to capture all the notes of Chopin's 48/1 on something less expressive than a piano would be easier.
My coauthor has her 10 year old learning Haskell from our book. This stuff does not have to be hard.
I can do whatever I want in Haskell.
I've got more news for you, since we have composition for things with more structure, it's still composable. (>=>) is like function composition, but for when we have monadic structure flying around. You can write all the loopy-woopy side-effecty whatevers you want. Haskell's just better at it and offers alternatives. The actual recursive loops are less spooky than the name "mapM_", but I didn't want to make it verbose.One of the nice things about Haskell is you can always replace a function with its contents, or factor something out into a function and call that function by name and the result never changes.