O'Reilly logo

Clojure for Finance by Timothy Washington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparing Clojure with FP and strong typing

Haskell is a statically typed programming language. The type system is a central part of the language and applies to all program elements, even at the most granular level. We'll take a look at how to implement the simple-moving-average function using this system:

module Main where import Data.List.Split(chop) type Prices = [Float] type AveragePrices = [Float] loadPrices :: FilePath -> IO Prices loadPrices path = do priceContents <- readFile path let priceLines = (lines priceContents) return (map (\x -> read x :: Float) priceLines) divvy :: Int -> Int -> [a] -> [[a]] divvy n m lst = filter (\ws -> (n == length ws)) choppedl where choppedl = chop (\xs -> (take n xs , drop m xs)) lst average :: [Float] -> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required