Hello everyone.
I have a problem with a assessment.
The problem is with the layout.
I cannot understand what is wrong.
Here is the code
module Main where
import IO
import System
import List
import Maybe
import Char
import Numeric
type Word=String
type WordCount=Int
type WordTup=(word,wordCount)
type WordList=[WordTup]
main=do args<-getArgs
textLines<-getText
switchArgs args textLines
where
switchArgs args textLines
|(isMemberOf "-f" args) && (isMemberOf "-i" args)
=printFreq(sortWordCount(parseLcLine textLines))
|(isMemberOf "-f" args)
=printFreq(sortWordCount (parseLine textLines))
|(isMemberOf "-i" args)
=printFreq(sortWordCount (parseLcLine textLines))
|otherwise
=printFreq(sortName (parseLine textLines))
getText::IO String
getText=do c<-getChar
e<-isEOF
if (e)
then return "" else
(do nc<-getText
return (:nc))
parseLine::String->Wordlist
parseLine line
|(line/="")&&(isWantedChar (headline))
=fillWordList w(parseLine newLine)
|(line/="")&&(not(isWantedChar (headline)))
=parseLine(tail line)
isMemberOf::String->[String]->Bool
isMemberOf arg args
=[]/=[a|a<-args,a==arg]
printFreq::WordList->IO()
printFreq wl=do sequence (map putWordStat wl)
where
putWordStat(Word,WordCount)->IO()
putWordStat(w,wc)
do putStr w
putSpc (20 (length w) (length(show wc)))
putStr (show wc)
putSpc 8
putStr (showFFloat (Just 2) (fromIntegral (wc) * 100.0/fromIntegral (wLength))"")
putChar '%'
putChar '\n'
return()
wlLength-countWords wl;
putSpc::Int->IO()
putSpc n
|n>1 do putChar ''
putSpc (n-1)
return()
|otherwise=putChar ''
countWords:Wordlist->Int
countWords [ ]
countWords ((w,wc):wl)=wc+countWords wl
sortName::WordList->WordList
sortName [ ] = [ ]
sortName (wn:ws)=sortName [(w,wc) (w,wc) <-ws,not (isGreater (w,wc)wc)]
++[wn]++sortName[(w,wc)|(w,wc)<-ws, isGreater (w,wc) wn]
where
isGreater (wl,wcl) (w2,wc2)
|ord(head(wl))-ord(head(x2))>0=True
|ord(head(wl))-ord(head(x2))<0=False
|length wl>l && length w2>l
=isGreater(tail(wl),wcl) (tail(w2,wc2)
|otherwise = []
where
w=parseWord line
newline=drop (length w) line
parseLcLine::String->WordList
parseLcLine line
|(line/="") && (isWantedChar (head line))=fillWordList w (parseLcLine newline)
|(line/="") && (not (isWantedChar (head line)))=parseLcLine (tail line)
|otherwise = []
where
w=map toLower (parseWord line)
newline=drop (lenfth w) line
parseWord::Word->Word
parseWord w
|(w/="") && (isWantedChar (head w))=(head w): parseWord (tail w))
|otherwise = ""
isWantedChar::Char->Bool
isWantedChar c
| (c=='a'|| c=='b'|| c=='c'|| c=='d'|| c=='e'|| c=='f'|| c=='g'|| c=='h'|| c=='i'|| c=='j'|| c=='k'|| c=='l'|| c=='m'|| c=='n'|| c=='o'|| c=='p'|| c=='q'|| c=='r'|| c=='s'|| c=='t'|| c=='u'|| c=='v'|| c=='w'|| c=='x'|| c=='y'|| c=='z'||c=='A'|| c=='B'|| c=='C'|| c=='D'|| c=='E'|| c=='F'|| c=='G'|| c=='H'|| c=='I'|| c=='J'|| c=='K'|| c=='L'|| c=='M'|| c=='N'|| c=='O'|| c=='P'|| c=='Q'|| c=='R'|| c=='S'|| c=='T'|| c=='U'|| c=='V'|| c=='W'|| c=='X'|| c=='Y'|| c=='Z'|| = True)
|otherwise = False
fillWordList::Word->WordList->WordList
fillWordList w wordlistl
|cWord/= [] =cWord++[wordl,wordCountl)|(wordl,wordCountl<-wordListl,wordl/=w]
|otherwise = (w,l):wordListl
where
cWord=[(wordl,(wordCountl-l)) | (wordl,wordCountl)<-wordListl,wordl==w]
|length w1>1 && length w2==1=True
|otherwise = False
sortWordCount::WordList->WordList
sortWordCount [] = []
sortWordCount ((wn,wcn):ws=sortWordCount [(w,wc|cw,wc)<-ws,ws<=wvn++
[(wn,wcn)]++sortWordCount [(cw,wc)|(w,wc)<-ws,wcs,wcn]