Idris2/tests/chez/chez025/runst.idr
2020-06-20 00:46:20 +01:00

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