layout problem
Γιώργος Κοσμίδης
gkosmidis@epsilon7.gr
Thu, 19 Sep 2002 10:19:57 +0300
Thanks for your answer.
The lines where as you asnwered me.
When I post my mail the layout was tottally ruined.
Here I post the program again but I have replaced all spaces with
underscores ( _ )
This is the error that I have: ERROR "c:\textanalysis.HS":48 - Syntax error
in declaration (unexpected `->')
Thanks in advance for all the help that you can give me
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]