I’m new to Haskell and have a problem with interact
function. This is my sample program:
main :: IO ()
main = interact inputLength
inputLength :: String -> String
inputLength input = show $ length input
It compiles but when running doesn’t print the output - just prints the string that is passed to it and moves to the next line. When I pass the interact
another String -> String
function like this:
upperCase :: String -> String
upperCase input = map toUpper input
it runs ok and prints the argument in uppercase as expected – so what is wrong with the first function?
interact
is still a lovely way to write command-line programs that are meant to work with pipes. WithIO
I am tempted to write non-composable user-only programs. – luqui