[Haskell-beginners] an observation about Haskell vs. Python

Ertugrul Söylemez es at ertes.de
Thu Sep 20 06:23:39 CEST 2012


Dennis Raddle <dennis.raddle at gmail.com> wrote:

> [...] In Haskell you give up easy-to-comprehend error messages and
> mutable data, and get back in reward a lot of reassurance that your
> program does what you meant and expressivity. (I realize Haskell has
> mutable data but it's not like Python's)

It is actually the same.  It's just that the assignment function is not
called "=", but instead, say, writeSTRef.  You could very well give it
an additional name, e.g. "~=":

    class Mutable m where
        type Ref m :: * -> *

        newRef :: a -> m (Ref m a)
        (~=)   :: Ref m a -> a -> m ()

    instance Mutable IO where
        type Ref IO = IORef
        newRef = newIORef
        (~=)   = writeIORef

    main = do
        x <- newRef 10
        x ~= 15
        {- ... -}

In fact Haskell generalizes this idea, because using lenses you can have
something similar even in state monads, which are actually pure and
don't use mutable variables.

Also I really doubt that there is any algorithm that has a shorter
and/or more readable implementation in Python from a language viewpoint.
It's really more a matter of what is predefined.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120920/c859dcc5/attachment.pgp>


More information about the Beginners mailing list