|
|
|
|
|
by tel
4823 days ago
|
|
do f1 <- fsStat "file1.txt"
f2 <- fsStat "file2.txt"
f3 <- fsStat "file3.txt"
let ratio = (size f1) / (sum $ map size [f1, f2, f3])
print ratio
Or, if you prefer a list do fs <- mapM fsStat files
let ratio = (size . head $ fs) / (sum . map size $ fs)
print ratio
And that seems to be one small example of why you may have already invented monads. I've been loving the impact of Javascript—modify and immediately see it on the browser—but every time I'm not using Haskell I miss it dearly. |
|
Perhaps people don't spot the link as easily because monads are usually explained in terms of a type system, and javascript is untyped? (Or perhaps just because Monad is a very abstract abstraction :)