[clean-list] Troubles about Vectors
Diederik van Arkel
dvanarkel@mac.com
Wed, 19 Nov 2003 23:06:19 +0100
On Nov 19, 2003, at 5:46 PM, Alves da Silva Cruz Willer wrote:
> Hello Cleaners,
>
> I've been working on a single DFT implementation but I've got in some
> troubles regarding vectors. Clean returns a share error, wich I can't
> understand and solve. The error message is something like this:
>
> "some" demanded attribute cannot be offered by shared object.
>
The "some" here is the '*' uniqueness attribute. In loop1 you are using
x1 and
y1 twice in the definition thus they are shared and not unique as your
type tries
to claim. Solution: either remove the uniqueness attribute or return x1
and y1 from
loop2 thus removing the sharing eg.
...
# (x1,y1,x2,y2) = loop2 i 0 m arg x1 y1 x2 y2
= loop1 (i+1) m dir x1 y1 x2 y2
loop2 :: Int Int !Int !Real *{#Real} *{#Real} *{#Real} *{#Real} ->
(*{#Real},*{#Real},*{#Real},*{#Real})
loop2 i k m arg x1 y1 x2 y2
| k == m = (x1,y1,x2,y2)
...
Regards,
Diederik van Arkel
> The testing code follows below. Has someone know what could be wrong
> with this code?
>
> module test
> import StdEnv
>
> Start = DFT 1 8 { 1.0 \\ i <- [1..8] } { 0.0 \\ i <- [1..8] }
> DFT :: !Int !Int *{#Real} *{#Real} -> (*{#Real},*{#Real})
> DFT dir m x1 y1
> #! m = size x1
> # x2 = { 0.0 \\ i <- [1..m] }
> # y2 = { 0.0 \\ i <- [1..m] }
> # (x2,y2) = loop1 0 m dir x1 y1 x2 y2
> | dir == 1 = ({ x/(toReal m) \\ x <-: x2},{ y/(toReal m) \\ y <-: y2})
> | otherwise = (x2,y2)
> where
> loop1 :: Int !Int !Int *{#Real} *{#Real} *{#Real} *{#Real} ->
> (*{#Real},*{#Real})
> loop1 i m dir x1 y1 x2 y2
> | i == m = (x2,y2)
> #! x2 = {x2 & [i]=0.0}
> #! y2 = {y2 & [i]=0.0}
> #! arg = (~(toReal dir))*2.0*3.141592654*(toReal i)/(toReal m)
> # (x2,y2) = loop2 i 0 m arg x1 y1 x2 y2
> = loop1 (i+1) m dir x1 y1 x2 y2
>
> loop2 :: Int Int !Int !Real *{#Real} *{#Real} *{#Real} *{#Real} ->
> (*{#Real},*{#Real})
> loop2 i k m arg x1 y1 x2 y2
> | k == m = (x2,y2)
> #! cosarg = cos ((toReal k)*arg)
> #! sinarg = sin ((toReal k)*arg)
> #! auxx = x2.[i]
> #! auxy = y2.[i]
> #! vx = x1.[k]
> #! vy = y1.[k]
> = loop2 i (k+1) m arg x1 y1 {x2 & [i]=(auxx + (vx*cosarg -
> vy*sinarg))} {y2 & [i]=(auxy + (vx*sinarg + vy*cosarg))}
> Thanks in advance,