{-# LANGUAGE BangPatterns #-}
-- |
module Statistics.Matrix.Function where

-- | Multiply a number by itself.
square :: Double -> Double
square :: Double -> Double
square Double
x = Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
x

-- | Simple for loop.  Counts from /start/ to /end/-1.
for :: Monad m => Int -> Int -> (Int -> m ()) -> m ()
for :: Int -> Int -> (Int -> m ()) -> m ()
for Int
n0 !Int
n Int -> m ()
f = Int -> m ()
loop Int
n0
  where
    loop :: Int -> m ()
loop Int
i | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n    = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
           | Bool
otherwise = Int -> m ()
f Int
i m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> m ()
loop (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
{-# INLINE for #-}