[Haskell-cafe] Functional vs Imperative
Thomas Davie
tom.davie at gmail.com
Tue Sep 13 11:42:47 EDT 2005
On 13 Sep 2005, at 16:22, David Roundy wrote:
> On Tue, Sep 13, 2005 at 01:45:52PM +0000, Dhaemon wrote:
>
>> Also, just for kicks, may I had this: I read the code of some
>> haskell-made
>> programs and was astonished. Yes! It was clean and all, but there
>> were "do"s
>> everywhere... Why use a function language if you use it as an
>> imperative
>> one?(i.e. most of the apps in http://haskell.org/practice.html)
>>
>
> Monadic code isn't synonymous with imperative code, and "do" only
> indicates
> that you're looking at monadic code. The Maybe monad is an example
> of a
> very useful, very non-imperative monad that can be used to cleanly
> write
> functional code.
>
> On the other hand, IO is always monadic, so perhaps you're looking
> at IO
> code. But I'd assert that even monadic IO code isn't quite the
> same as
> true "imperative" code. I'd probably say that the difference has
> to do
> with whether you create modifiable "variables". When you start
> doing that,
> whether you're in the ST monad or the IO monad, I think you're writing
> imperative-style code. But I think that that sort of usage is
> actually
> pretty uncommon.
I would tend to argue that even in those monads you aren't really
writing imperative style code -- you still can't have side effects.
The point of the monad is that it preserves referential transparency
while doing something ordered.
Bob
More information about the Haskell-Cafe
mailing list