Edited by zmir, 09 August 2011 - 12:14 PM.
1 reply to this topic
#1
Posted 04 August 2011 - 01:54 PM
...
|
|
|
#2
Posted 05 August 2011 - 03:59 PM
All right, are you using this program by piping file data through stdin?
Also, your count method wouldn't compile. Length can't be passed to x as x is expected to be a Char type, which doesn't accept a function of type ([a] -> Int) as an argument. I think you're trying to do something more like this:
echo "Peter" | ./my_programgetContents retrieves the entirety of the user input up until an EOF is encountered, and is evaluated lazily. What this means is that in methods that print values without reaching the end of the input, this produces a very simple method of writing interactive user input using lines.
Also, your count method wouldn't compile. Length can't be passed to x as x is expected to be a Char type, which doesn't accept a function of type ([a] -> Int) as an argument. I think you're trying to do something more like this:
count :: Ord a => [a] -> [(a, Integer)] count = map (\x -> (head x, length x)) . group . sortWhich is an okay solution, but won't work too well if you don't separate the input by lines first, as the program will wait for the user to finish writing the input, as the length function does not return until it goes through the entire list. You should split up your input and go through it line by line in freqs.
freqs :: String -> IO () freqs str = sequence_ (map (putStrLn . show) $ map count $ lines str)This should produce results each time you press enter. :) Then main can be implemented like this:
main = getContents >>= freqs
Wow I changed my sig!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









