3 ms·
I've found there are situations where primitives are fine and wrapping doesn't add much value, e.g., (using F#) let calcCorrelation (symbol1:string) (symbol2
by clausok 8y ago
I've found there are situations where primitives are fine and wrapping doesn't add much value, e.g., (using F#)
let calcCorrelation (symbol1:string) (symbol2:string) = ...
Here, calling the function with misordered arguments won't change the result, so the wrapping\unwrapping friction doesn't have much ROI.
but here, where 'beta' is the slope of a least-squares fitted line:
let calcBeta (stockSym:string) (indexSym:string) = ...
that's a mistake waiting to happen, because if you accidentally flip the arguments when you call the function you get a different number. Better to have:
type StockSymbol = StockSymbol of string
type IndexSymbol = IndexSymbol of string
let calcBeta (IndexSymbol index) (StockSymbol stock) = ...
then call the function like this:
let beta = calcBeta (IndexSymbol "SPX") (StockSymbol "AMZN")
Of course you could still make a mistake:
let beta = calcBeta (IndexSymbol "AMZN") (StockSymbol "SPX")
but that would stick out like a sore thumb.