[clean-list] slown down by time annotation
Valéry Croizier
valery at freesurf.fr
Thu Jul 14 19:09:23 MEST 2005
Flam returns an unboxed array,
flam :: *{#Int} -> *{#Int}
so the compiler knows that t
t = flam {{x+1 \\ x <- [1..n]} & [n-1] = 1}
is unboxed, and the type declaration
t :: *{#Int}
is only a confirmation of what the compiler already knows. But the compiler is confused and calls the reverslice function 3 times instead of 1. Maybe it is a bug.
erik.zuurbier at tiscali.nl a écrit :
>Valery,
>
>If you don't have the type annotation, the array is a sequence
>of pointers to other fields in the heap that contain the individual
>integers.
>
>If you DO have the type annotation, the arrya is a sequence
>of the actual integers themselves. That is usually a lot faster and it
>saves space. But there are cases where they cannot be used. That has to
>do with laziness.
>
>Regards Erik Zuurbier
>
>----Oorspronkelijk
>bericht----
>Van: valery at freesurf.fr
>Datum : 14/07/2005 14:51
>Aan:
><clean-list at science.ru.nl>
>Onderw: [clean-list] slown down by time
>annotation
>
>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
>
>
>
>
>
>_______________________________________________
>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