traverseDirectoryIO
Write a new function, traverseDirectoryIO , that has the type:
| | traverseDirectoryIO :: FilePath -> ( FilePath -> IO a) -> IO [a] |
This function should behave like traverseDirectory’ but should accept a function returning an IO action, rather than a value.
Timing Pure Functions
The timeFunction that you built as you worked through this chapter only supports timing IO actions. Try writing a version of this function that also works for pure values, with the type:
| | timePureFunction :: Metrics -> String -> a -> IO a |
What are the limitations to your implementation function? Are there things that a user of the function could do to ensure that the timing information was better?
Metrics Strictness
Consider the MetricsStore type that you defined earlier in this chapter:
| | data MetricsStore = MetricsStore |
| | { successCount :: Int |
| | , failureCount :: Int |
| | , callDuration :: Map . Map String Int |
| | } deriving ( Eq , Show ) |
How might you make use of strictness to improve the performance of metrics? Try writing some metrics collecting functions using several different approaches to strictness and profiling the results.
Footnotes
[18]
https://downloads.haskell.org/ghc/latest/docs/html/users_guide/index.html
Copyright © 2023, The Pragmatic Bookshelf.