[clean-list] slown down by time annotation
erik.zuurbier at tiscali.nl
erik.zuurbier at tiscali.nl
Thu Jul 14 15:31:17 MEST 2005
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
More information about the clean-list
mailing list