Last generator in do {...}

I am sure there are a billion errors in this. This is the first one: Line:17 - Last generator in do {...} must be an expression Can Anyone point the errors and maybe tell me if there is a possibility for this to work? import IO import System import List import Maybe import Char import Numeric type Name=String type Room=Int type Dr=String type PatientTup=(Name,(Room,Dr)) type PatientList=[PatientTup] main=do userText<-getText ----------------------------------------------------------------------------------- ________getText::IO String ________getText=do nc<-getText ___________________return (:nc) ----------------------------------------------------------------------------------- ________PatientList::[(String,(Int,String))] ________PatientList=[("Robson, Brian",(2,"MJH")), _____________________("Hitchin, Linda",(1,"ILR")), _____________________("Reeve, Paul", (2,"ILR"))] ----------------------------------------------------------------------------------- ________getWards::Int->Int ________getWards PatientList=[Room | (Name,(Room,Dr)) <- PatientList, Room==getText] _________________do putSpc (length Room) _________________return(RoomLength) ----------------------------------------------------------------------------------- ________getPatient::String->String ________getPatient PatientList=[Name,Room,Dr | (Name,(Room,Dr)) <- PatientList, Name==getText] ___________________do putChar (Name) ______________________putChar 'is in ward' ______________________putChar (Room) ______________________putChar 'and is treated by' ______________________putChar (Dr) ______________________return (wl) ----------------------------------------------------------------------------------- ________printFreq::WordList->IO() ________printFreq wl ----------------------------------------------------------------------------------- ________NumberInWard::printFreq(getWards(getText)) ----------------------------------------------------------------------------------- ________PatientInfo::printFreq(getPatient(getText)) ----------------------------------------------------------------------------------- ________setABC::ReceptionReport -> ReceptionReport ________setABC [ ]___=[ ] ________setABC(wn:ws)=setABC[(w,wc) | (w,wc)<-ws, not(isBigger(w,wc)wn)] _________++[wn]++setABC[(w,wc) | (w,wc) <- ws, isBigger (w,wc) wn] __________________where ___________________isBigger (w1,wc1) (w2,wc2) ____________________| ord(head(w1))-ord(head(w2))>0=True ____________________| ord(head(w1))-ord(head(w2))<0=False ____________________|length w1>1&&length w2>1 _____________________=isBigger(tail(w1),wc1) (tail(w2),wc2) ____________________|length w1>1&&length w2==1=True ____________________|otherwise=false ----------------------------------------------------------------------------------- ________ReseptionList::String->String ________ReseptionList PatientList=[Name,Room | (Name,(Room,Dr)) <- PatientList] ______________________do sequence (map ReceptionReport wl) __________________________________where ______________________________________ReceptionReport::setABC((Name,Room))->IO() ______________________________________ReceptionReport(w,wc)=do putStr w _______________________________________________________________putStr (show w) _______________________________________________________________putChar 'in' _______________________________________________________________putStr (show wc) _______________________________________________________________putChar '\n' _______________________________________________________________return wl ----------------------------------------------------------------------------------- ________setNum::DoctorsReport -> DoctorsReport ________setNum [ ] = [ ] ________setNum((wn,wcn):DoctorsReport[(w,wc)|(w,wc)<-ws, _________________________ws<=wcn++[(wn,wcn)]DoctorsReport[(w,wc)|(w,wc)<-ws,wc>wcn] ----------------------------------------------------------------------------------- ________DoctorsList::String->String ________DoctorsList PatientList=[Name,Room | (Name,(Room,Dr)) <- PatientList, Dr==getText] ____________________do sequence (map DoctorsReport wl) ________________________________where ____________________________________DoctorsReport::setNum((Name,Room))->IO() ____________________________________DoctorsReport(w,wc)=do putStr w ___________________________________________________________putStr (show w) ___________________________________________________________putChar 'in' ___________________________________________________________putStr (show wc) ___________________________________________________________putChar '\n' _______________________________________________________________return wl -----------------------------------------------------------------------------------

On Tue, Oct 29, 2002 at 11:20:47AM +0200, George Kosmidis wrote:
I am sure there are a billion errors in this. This is the first one:
Line:17 - Last generator in do {...} must be an expression Can Anyone point the errors and maybe tell me if there is a possibility for this to work?
I strongly recommend getting started with a MUCH simpler function, and starting out with some of the excellent tutorials available on the web. It looks like you are trying to do imperative programing here, rather than functional programming. In fact, it looks like it would be much easier to translate your program into pascal, rather than into haskell. A few errors:
main=do userText<-getText ________getText::IO String
It looks here sort of like you're trying to declare the getText function within main. All declarations are 'top level' in haskell, so this won't work.
________PatientList=[("Robson, Brian",(2,"MJH")), _____________________("Hitchin, Linda",(1,"ILR")), _____________________("Reeve, Paul", (2,"ILR"))]
All functions in haskell start with a lowercase letter (or a punctuation, if it's an inline function), never with capital letter.
________getWards::Int->Int ________getWards PatientList=[Room | (Name,(Room,Dr)) <- PatientList, Room==getText]
This syntax doesn't exist for defining what I think you're intending to be a variable, 'PatientList'.
_________________do putSpc (length Room) _________________return(RoomLength)
do is only used (by beginners anyways, there are other uses, but they're much more advanced) by functions which return an IO monad, which should generally be a small minority of your functions. Almost every time you use 'do' in your program, it is just plain wrong. Basically, you should start out with a single function and a main that prints its result, and work up from there, testing your code each time you add a new function. I recommend starting with the "Gentle Introduction" (http://www.haskell.org/tutorial/). Good luck on your haskelling! -- David Roundy http://civet.berkeley.edu/droundy/

G'day all. On Tue, Oct 29, 2002 at 11:20:47AM +0200, George Kosmidis wrote:
I am sure there are a billion errors in this. This is the first one: Line:17 - Last generator in do {...} must be an expression
What this means is that the compiler has interpreted the last line of a do expression to be a generator (i.e. pat <- exp), which is bad Haskell. In your case, here is main:
main=do userText<-getText
Occasionally, this may be caused by offside errors: main = do foo <- bar return foo ^ offside error, Haskell interprets this as not being part of the do expression Cheers, Andrew Bromage

On Wed, 30 Oct 2002, Andrew J Bromage wrote: (snip)
main = do foo <- bar return foo ^ offside error, Haskell interprets this as not being part of the do expression
Gosh, I find that unintuitive, given, say, http://www.zvon.org/other/haskell/Outputsyntax/doQexpressions_reference.html - though I'd also been surprised to not be able to get away with, let square = x ellipse = y in ... so clearly the offside rule is still capable of confusing me. I should go re-read a FAQ perhaps! (-: -- Mark
participants (4)
-
Andrew J Bromage
-
David Roundy
-
George Kosmidis
-
Mark Carroll