September 2017
Beginner to intermediate
396 pages
9h 46m
English
stack new working-with-rank-n-type simple
module Main where
import Control.Monad.ST import Data.STRef import Control.Monad
factorialST :: (Num t, Eq t) => t -> STRef s t -> ST s t factorialST 0 x = readSTRef x factorialST n x = do x' <- readSTRef x writeSTRef x $! x' * n factorialST (n-1) x
factorial n = runST $ do x <- newSTRef 1 factorialST n x
main :: ...Read now
Unlock full access