I agree with ja that you should split your code into two functions:
- The clean part: a function that takes your data structure and turns it into a string
- The unclean part that prints this line to the console
Here's a simple implementation:
showTable :: Table -> String showTable xs = concatMap format xs where format (a, b) = a ++ " : " ++ b ++ "\n" display :: Table -> IO () display table = putStr (showTable table)
This design has two advantages:
Firstly, most of your βlogicβ is in the clean part of the code, which is nice in functional programming.
Secondly, it is just a simple software development principle; you now have a reuse function that you can use if you ever want to format the data structure in another part of your code (seems likely).
source share