[clean-list] observers in your plans?

Carlos Aya carlosayam at yahoo.com.au
Sun Nov 29 15:51:22 MET 2009


Thanks John for pointing this.

I read that section but seemed too obscure to me initially... 

regards
Carlos



----- Original Message ----
From: John van Groningen <johnvg at cs.ru.nl>
To: Carlos Aya <carlosayam at yahoo.com.au>
Cc: clean-list at cs.ru.nl
Sent: Sat, 28 November, 2009 12:59:16 AM
Subject: Re: [clean-list] observers in your plans?


Carlos Aya  wrote:

>Just curious if you have among the plans, implementation of so-called observer types, i.e. variables that do not add as counting occurences.

Clean already observer references, see section 9.4 of the reference manual.

For example, size can be used in a guard or in a #! as an observer.

>The problem with the following function ...
>
>doIt :: *(a e) (Int -> e) -> *(a e) | Array a e
>doIt arr f = {arr & [i] = f i \\ i <- [0.. (size arr)]}
>
>... is that (size arr) counts as occurrence in the body of doIt, so arr cannot be unique. But as seen in the _SystemArray implementation, size only reads the size of the array which we know is fixed. So, truly its signature should be
>
>size :: 0:arr -> Int
>
>(I put 0: to indicate an "observed" parameter, out of my ignorance.. and based on Odersky paper...)

This should work:

doIt arr f
    #! s = size arr
    = {arr & [i] = f i \\ i <- [0.. s-1]}

or you could use usize instead:

doIt arr f
    # (s,arr) = usize arr
    = {arr & [i] = f i \\ i <- [0.. s-1]}

Kind regards,

John van Groningen



      __________________________________________________________________________________
Win 1 of 4 Sony home entertainment packs thanks to Yahoo!7.
Enter now: http://au.docs.yahoo.com/homepageset/



More information about the clean-list mailing list