repl.it
@Pzixel/

PeruFantasticCosmos

Haskell

No description

fork
loading
Files
  • main.hs
main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{-# LANGUAGE Safe #-}
 
import Control.Monad.ST
import Data.STRef
import Control.Monad

factorialST :: Int -> Int
factorialST n = runST $ do           
                result <- newSTRef 1            
                forM_ [2..n] $ \x -> do       
                    modifySTRef result (*x) 
                readSTRef result

main = print $ factorialST 5
GHCi, version 8.6.5
?