mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-21 02:31:50 +03:00
16 lines
329 B
Idris
16 lines
329 B
Idris
|
import Data.Ref
|
||
|
|
||
|
stsum : Num a => List a -> a
|
||
|
stsum xs
|
||
|
= runST $
|
||
|
do acc <- newRef 0
|
||
|
add xs acc
|
||
|
readRef acc
|
||
|
where
|
||
|
add : List a -> STRef s a -> ST s ()
|
||
|
add [] ref = pure ()
|
||
|
add (x :: xs) ref
|
||
|
= do acc <- readRef ref
|
||
|
writeRef ref (acc + x)
|
||
|
add xs ref
|