3 ms·
In Haskell you can use do blocks like: Monads in Haskell were exactly the example I had in mind when I wrote my previous post. As you say, you can use ‘do’ not
by Chris_Newton 13y ago
In Haskell you can use do blocks like:
Monads in Haskell were exactly the example I had in mind when I wrote my previous post. As you say, you can use ‘do’ notation in simple cases, but it’s just syntactic sugar and the unsugared version quickly becomes unwieldy if you need more flexibility.
Edit: A good case study is the not-quicksort quicksort that gets used all over the place as a demonstration of Haskell’s elegance. Something closer to a real quicksort is rather less tidy: http://www.haskell.org/haskellwiki/Introduction/Direct_Translation http://www.haskell.org/haskellwiki/Introduction/Direct_Trans...
The big difficult in going from imperative to functional languages is thinking about data structures as immutable.
That’s certainly one of the big jumps, but I don’t think it’s the whole story. You can do a lot with purely functional data structures, given a bit of time to get your head around them, but sometimes you might still have good reasons to work with mutable data instead. That can be very clumsy when shoehorned into a primarily functional programming language.
I’m hoping that one of the next big steps forward in programming language design will be providing much better control of externally observable behaviour, but without forcing a purely functional style or requiring prohibitive amounts of boilerplate code. I’d like to program in a style that is declarative by default and provides powerful tools for working with functions, but also with the ability to break out of that immutable world in controlled ways as easily as writing imperative code and as safely as writing code with a good type system today.
- tome 13y ago> As you say, you can use ‘do’ notation in simple cases, but it’s just syntactic sugar and the unsugared version quickly becomes unwieldy if you need more flexibility. I've actually found that it's much better to compose monadic functions with (<=<) than use long do blocks. It forces you to structure your code much more appropriately.