Haskell Program to convert string to lower case
Program
import Data.Char
main = do
putStrLn "Enter your name:"
name <- getLine
putStrLn "Converted to lower case: "
putStrLn $ map toLower name
This Haskell program converts a user-input string to lowercase and prints the result.
-
import Data.Char- Imports the
Data.Charmodule, which provides character-related functions liketoLower.
- Imports the
-
main = do- Defines the
mainfunction for handling input and output operations.
- Defines the
-
putStrLn "Enter your name:"- Prints a prompt asking the user to enter a name.
-
name <- getLine- Reads user input as a string and stores it in the
namevariable.
- Reads user input as a string and stores it in the
-
putStrLn "Converted to lower case: "- Prints a message indicating that the string will be converted to lowercase.
-
putStrLn $ map toLower name- Uses
map toLowerto convert each character innameto lowercase. toLoweris a function fromData.Charthat converts individual characters to lowercase.mapappliestoLowerto each character in the string.putStrLnthen prints the modified string.
- Uses
Output
$ ghc convert_tolower.hs
[1 of 1] Compiling Main ( convert_tolower.hs, convert_tolower.o )
Linking convert_tolower ...
$ ./convert_tolower
Enter your name:
OODLESCOOP
Converted to lower case:
oodlescoop