closing file handles

Lyndon While lyndon@cs.uwa.edu.au
Tue, 11 Sep 2001 09:06:12 +0800


At 9:44 am -0700 10/9/2001, Hal Daume wrote:
>Simon Marlow wrote:
>  >     go' f
>  >         = do h    <- openFile f ReadMode
>  >              text <- hGetContents h
>  >                  let c = head text
>  >                  c `seq` do { hClose h; return c }
>
>This doesn't compile for me.  It complains that the last statement in a
>'do' construct must be an expression...what gives?

There's a layout error - the statements in the do should be left-aligned:

go' f
     = do h    <- openFile f ReadMode
          text <- hGetContents h
          let c = head text
          c `seq` do { hClose h; return c }

It's probably caused by different systems having different tab-settings.

(This may be stricter than the actual requirement, but there's no 
harm in that...)

--
Dr. Lyndon While

--------
Email  - lyndon@cs.uwa.edu.au                        ,-_|\
Phone  - +61 8 9380 2720                            /     \
Fax    - +61 8 9380 1089                            *_,-._/
Web    - http://www.cs.uwa.edu.au/~lyndon                v