[clean-list] Operator :=

Ronny Wichers Schreur ronny@cs.kun.nl
Wed, 27 Sep 2000 23:25:06 +0200


Eduardo Costa wrote:

>pMaiusculas :: String-> String
>pMaiusculas xs= (loop xs 0, xs)
>where
>        sz= size xs-1
>        loop s i | i > sz= s
>        loop s i
>        = loop (s := (i, toUpper s.[i])) (i+1)

(The implementation doesn't match the type.)

>The intention was to convert a String to upper case. I
>thought that the program would update s in place. It seems
>that this is not what is going on. If the operator := is
>making a copy of s at each iteration, why is it necessary
>in the language?

:= is not part of the language, it's just an operator defined
in StdString. It may have been there before uniqueness typing.
It certainly was there when String was still an atomic type
and not an array of unboxed characters.

>ZF operations should be enough.

You can write this function with a single array comprehension

    pMaiusculas :: String -> .String
    pMaiusculas xs
        =   {toUpper c \\ c <-: xs}


Cheers,

Ronny Wichers Schreur