[clean-list] observers in your plans?

John van Groningen johnvg at cs.ru.nl
Fri Nov 27 14:59:16 MET 2009


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


More information about the clean-list mailing list