It just means you are trying to directly access a list element by its index in a list that doesn't have that many elements.  It is probably somewhere in your floatData function, which you did not list.  When you don't print it out to screen, haskell does not bother to evaluate it and therefore it never hits that error.  If you didn't use that operator, then it is used in some library you are using.

Prelude> [1,2,3] !! 5
*** Exception: Prelude.(!!): index too large


On Thu, Apr 4, 2013 at 1:49 PM, Roger Mason <rmason@mun.ca> wrote:
Hello,

The following fragment compiles but causes a runtime error:

Prelude.(!!): index too large

If I comment out the line 'hPutStr outh ( show ncat)' the program runs fine (but there is no output, of course).

Thanks for any help.

Roger

writeOutput infile outfile list fox mw nox ncat units = do
          inh <- openFile infile ReadMode -- the file of analyses, one per line
          outh <- openFile outfile WriteMode
          mainloop inh outh list fox mw nox ncat units
          hClose outh
          hClose inh

-- the calculations are here
mainloop inh outh list fox mw nox ncat units = do
             ineof <- hIsEOF inh
             if ineof
                     then do
                         print list      -- For testing/debugging only
                         return ()
                     else do
                   inpStr <- hGetLine inh
                   let list' = inpStr:list
                           let dat = floatData list' -- the analytical input data
                           let ta = zipWith (/) dat units                            -- convert all to wt%
                           let moles = zipWith (/) ta mw
                           let apo = zipWith (*) nox moles
                           let factor = fox/(sum apo)
                           let nanions= (map (* factor) apo)
                           let catox = zipWith (/) ncat nox
                           let ncat = zipWith (*) catox nanions
                           hPutStr outh ( show ncat)
                   mainloop inh outh list' fox mw nox ncat units

This electronic communication is governed by the terms and conditions at
http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2012.php

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners