- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Haskell Program to determine the name and version of the operating system
This tutorial discusses writing a program to find the operating system info in the Haskell programming language.
Haskell provides functions to find the system info. These functions can be accessed by importing the Info module from the System package in Haskell.
In this tutorial, we see
- Program to display the name of the Operating System.
- Program to display the architecture of the processor.
- Program to display the compiler name.
- Program to display the compiler version.
Syntax
To import a module in Haskell the syntax is to follow.
import packageName.moduleName
To import the Info module from the system package the syntax.
import System.Info
Now all the functions in the Info module are accessible to the program.
Example 1
Program to display the name of the Operating System
-- importing Info module from System package import System.Info main = do -- printing the name of the operating system print ("Name of the operating system is:") print(os)
Output
"Name of the operating system is:" "linux"
In the above program, we imported the Info module from the system package. In the main function, we invoked a function os (os :: [Char]), which is a built-in function in the Info module that returns the name of the Operating System. Finally, printed the returned output using the print function.
Example 2
Program to display the architecture of the processor.
-- importing Info module from System package import System.Info main = do -- printing the architecture of the processor print ("The architecture of the processor is:") print(arch)
Output
"The architecture of the processor is:" "x86_64"
In the above program, we imported the Info module from the System package. In the main function, we invoked a function arch (arch :: [Char]), which is a built-in function in the Info module that returns the name of the architecture of the processor. Finally, printed the returned output using the print function.
Example 3
Program to display the Compiler Name.
-- importing Info module from System package import System.Info main = do -- printing the name of the compiler print ("The name of the compiler is:") print(compilerName)
Output
"The name of the compiler is:" "ghc"
In the above program, we imported the Info module from the System package. In the main function, we invoked a function compilerName (compilerName :: [Char]), which is a built-in function in the Info module that returns the name of the compiler used to compile the code. Finally, printed the returned output using the print function.
Example 4
Program to display the Compiler version
-- importing Info module from System package import System.Info main = do -- printing the version of the compiler print ("The version of the compiler is:") print(compilerVersion)
Output
"The version of the compiler is:" Version {versionBranch = [8,6], versionTags = []}
In the above program, we imported the Info module from the System package. In the main function, we invoked a function compilerVersion (compilerVersion :: [Char]), which is a built-in function in the Info module that returns the compiler version used to compile the code. Finally, printed the returned output using the print function.
Conclusion
In this tutorial, we discussed implementing programs to find the system information in the Haskell programming language.