2 ms·
> Good point, languages like JavaScript support both imperative AND declarative/functional styles. A language that lets you do both covers more use cases than a
by eru 11y ago
> Good point, languages like JavaScript support both imperative AND declarative/functional styles. A language that lets you do both covers more use cases than a language that only does one.
For what's it worth, some people refer to Haskell as their favourite imperative language. And they are only semi-joking: while the library ecosystem is firmly in the camp of functional idioms, imperative programming is Haskell is pretty nice and straightforward---you'll just have to tag your code with eg IO or the State Monad.
- spion 11y agoIf you use the ST monad instead of State, you get actual mutable variables. STArray lets you write typical imperative algorithms that work with mutable arrays, like sieve of Eratosthenes or dynamic programming. Imperative sieve of Eratosthenes: https://gist.github.com/rik0/1171446#file-erat1-hs https://gist.github.com/rik0/1171446#file-erat1-hs
- eru 11y agoYes. Though sieve of Eratosthenes really cries out for a sort-of-lazy infinite array.