[clean-list] slown down by time annotation

Arjen van Weelden arjenw at cs.ru.nl
Sat Jul 16 16:18:26 MEST 2005


Hi,

I you give a type to ANY expression in a where clause, it becomes a
function (and is lifted internally).
The array is therefore no longer shared. This explains the slowdown that
is caused by the three uses of the array, which is constructed three times.
Please try adding t` = t to the where clause and using t` in the body of
the function (instead of t).
I don't think that this behaviour is documented anywhere, and I agree that
it is not what you would expect.

regards,
	Arjen

On Thu, 14 Jul 2005, [ISO-8859-1] Valéry Croizier wrote:

> Hello Clean users.
>
> I have written a few programs to taste the language, and the one below
> is about arrays.
> What puzzles me is the type annotation commented out in 'showflam',
> which makes the program 3 times slower.
>
> Can anybody explain me what's happening ?
>
> Valery.
>
> swap :: *{#Int} !Int !Int -> *{#Int}
> swap t i j
>   #! ti = t.[i]
>   #! tj = t.[j]
>   = {t & [i] = tj, [j] = ti}
>
> reverslice :: !Int !Int *{#Int} -> *{#Int}
> reverslice i j t
>   | i < j     = reverslice (inc i) (dec j) (swap t i j)
>   | otherwise = t
>
> flam :: *{#Int} -> *{#Int}
> flam t
>   #! end = t.[0]
>   | end == 1 = t
>   | otherwise  = flam (reverslice 0 (end - 1) t)
>
> showflam :: !Int -> [Int]
> showflam n
>   #! t1 = t.[1]
>   #! t2 = t.[n / 2]
>   #! t3 = t.[n - 1]
>   = [ t1, t2, t3 ] where
> //  t :: *{#Int} // slows down 3X
>   t = flam {{x+1 \\ x <- [1..n]} & [n-1] = 1}
>
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list
>




More information about the clean-list mailing list