Go Back   Dynamic Drive Forums > General Coding > Other
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-17-2009, 12:25 AM
qzpmqzpm qzpmqzpm is offline
New Comer (less than 5 posts)
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Haskell-word count

1) Script Title: Haskell-word count

2) Script URL (on DD):



3) Describe problem:


For example: when count: putStr(count "The world the Spain") it should produce:

the.............................2
world...........................1
spain...........................1 thats the way I want


but in this code, it produces:

the....................... **
world.................... *
spain......................*

I dont want this way.


and the below is the following codes:

-- Word frequency count.
module Count where

import List
import Char






-- Convert an input text to a text representation of a count of
-- frequencies of words in the original text.
--
-- There is a line of output for each distinct word of the input,
-- ignoring punctuation and case, consisting of
-- * the word (padded on the left so that the right ends of the words
-- are vertically aligned,
-- * a space followed by as many asterisks as there were occurrences
-- of the word in the input.
-- The words are listed in alphabetical order.

count :: String -> String
count s =
unlines [count_line (pad width (head ws)) (length ws) | ws <- groups]
where
-- list of groups of identical words in the input
groups = group(sort [normalize w | w <- words s])

-- width of the longest word in the input
width = maximum[length (head ws) | ws <- groups]

-- a line of the count for word w with n occurrences
count_line :: String -> Int -> String
count_line w n = w ++ "" ++ replicate 48 '.'


-- The string consisting of letters and hyphens from the input string,
-- converted to lower case.
normalize :: String -> String
normalize cs = [toLower c | c <- cs, isAlpha c || c == '-']


-- pad s n is a string formed by adding enough spaces in front of s to
-- make a string of length at least n.
pad :: Int -> String -> String
pad n s = replicate (1 - length s) ' ' ++ s


please help

Last edited by jscheuer1; 10-17-2009 at 10:20 AM. Reason: Remove Broken Link
Reply With Quote
  #2  
Old 11-04-2009, 10:16 PM
Trinithis Trinithis is offline
Senior Coders
 
Join Date: May 2007
Location: USA
Posts: 371
Thanks: 2
Thanked 4 Times in 4 Posts
Default

http://www.dynamicdrive.com/forums/s...=haskell+count
__________________
Trinithis
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:55 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.