π Error.hs file
Module Documentation: Error
ErrorThe Error module in Haskell is designed to manage configuration settings and handle error reporting for a file conversion application. It encapsulates the logic required to parse command line arguments, manage configurations for input and output formats, and provide error handling.
Interface and Functionality Overview
Data Types
Conf: A data structure to hold the configuration settings.inputFile: Represents the input file path.outputFile: Represents the output file path.inputFormat: Stores the format of the input file as an integer.outputFormat: Stores the format of the output file as an integer.
Constants for File Formats
markDown: Integer constant representing the Markdown format.json: Integer constant representing the JSON format.xml: Integer constant representing the XML format.
Functions
modifConf
Purpose: Modifies the configuration based on the command line flags and values.
Parameters:
c: The current configuration (Conf).The flag (e.g., "-i", "-e", "-o", "-f") indicating what aspect of the configuration to modify.
v: The new value to be applied.
Returns: A new
Confobject modified according to the specified flag and value, wrapped inMaybefor error handling.
getOpts
Purpose: Iteratively processes a list of command line arguments to update the configuration.
Parameters:
conf: Initial or current configuration (Conf).list: List of strings representing command line arguments.
Returns: The final configuration after processing all arguments, wrapped in
Maybeto handle potential errors in argument processing.
errorHandling
Purpose: Provides a high-level interface to handle the parsing of command line arguments and return an appropriate message or configuration.
Parameters:
args: A list of strings representing command line arguments.
Returns: Either an error message (
Left String) or a valid configuration (Right Conf).
Key Concepts
Error Reporting: Through the use of the
Eithertype, the module effectively communicates errors in argument parsing or configuration modification.Modularity: By segregating the handling of different formats and file paths into a single configuration object (
Conf), the module promotes clean and modular code.Flexibility: The system can easily be expanded to support additional file formats or configuration options by modifying the
Confdata structure and the associatedmodifConffunction.
Last updated