Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Prelude.(!!): index too large (Roger Mason)
   2. Re:  Prelude.(!!): index too large (David McBride)
   3. Re:  Prelude.(!!): index too large (Roger Mason)
   4.  code review (Chris Bolton)
   5.  Vertices and Indices (Adrian May)
   6. Re:  Vertices and Indices (Tom Davie)


----------------------------------------------------------------------

Message: 1
Date: Thu, 04 Apr 2013 15:19:49 -0230
From: Roger Mason <[email protected]>
Subject: [Haskell-beginners] Prelude.(!!): index too large
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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



------------------------------

Message: 2
Date: Thu, 4 Apr 2013 14:24:39 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Prelude.(!!): index too large
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <can+tr43mxo0fao6gqefcqkpmqee+zbho-87pc2x2t4yxqdv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 <[email protected]> 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<http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2012.php>
>
> ______________________________**_________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130404/ee1f3487/attachment-0001.htm>

------------------------------

Message: 3
Date: Thu, 04 Apr 2013 16:17:41 -0230
From: Roger Mason <[email protected]>
Subject: Re: [Haskell-beginners] Prelude.(!!): index too large
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,

Thanks for the response
On 04/04/2013 03:54 PM, David McBride wrote:
> 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.
>
I cleaned up the code layout and the error has now been replaced by another:

f: <<loop>>

The complete code (below) is pretty ugly.  If anyone has a few minutes 
to look it over and suggest a source for the error that would be very 
helpful.

Thanks,
Roger

import System.Environment       -- For command line args
import System.IO                -- For, er, IO
import System.Exit              -- For early parole

main = do
        cmdLineArgs              -- Check only
        args <- getArgs
        let consts = args !! 1
        let list = []
        loadFile consts list   -- Read file containing mol wts etc into 
'list'
        let analytes = head list -- Names of analysed components (oxid, 
element...)
        let mw       = floatData ( (processData list) !! 1 ) -- Weight 
(amu) of analyte
        let nox      = floatData ( (processData list) !! 2 ) -- Oxygens 
in oxide formula
        let ncat     = floatData ( (processData list) !! 3 ) -- Cations 
in oxide formula
        let units    = floatData ( (processData list) !! 4 ) -- 1 = wt%; 
1E4 = ppm
        let list = []
        let fox = read (args !! 0) :: Float -- number of oxygens in f.u.
        let analyses = args !! 2
        let outfile  = args !! 3
        loadFile analyses list  -- Read file containing analyses into 'list'
        writeOutput analyses outfile list fox mw nox ncat units -- Write 
recalculated formulae into outfile
        mapM_ putStrLn list

loadFile consts list = do
     inh <- openFile consts ReadMode
     list <- hGetContents inh
     hClose inh

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
                                  dat = floatData list' -- the 
analytical input data
                                  ta = zipWith (/) dat 
units                            -- convert all to wt%
                                  moles = zipWith (/) ta mw
                                  apo = zipWith (*) nox moles
                                  factor = fox/(sum apo)
                                  nanions= (map (* factor) apo)
                                  catox = zipWith (/) ncat nox
                                  ncat = zipWith (*) catox nanions
                              hPutStr outh ( show ncat)
                              mainloop inh outh list' fox mw nox ncat units


cmdLineArgs = do
    args <- getArgs
    usage (length args)                  -- check 'em

usage :: Int -> IO ()
usage nargs
       | nargs < 4 = fallOverAndDie "Usage: formula 'ox in formula' 'mol 
wt. file' 'analysis file' 'output file'."
       | otherwise = putStrLn "Input looks OK"

fallOverAndDie :: String -> IO a
fallOverAndDie err = do putStrLn err
                         exitWith (ExitFailure 1)

-- Convert the input numbers from strings to floats
floatData :: [String] -> [Float]
floatData inList = map read inList::[Float]

-- Split input file into lines & words
processData :: String -> [[String]]
processData inpStr = do
             let thelines = lines inpStr
             let thewords = map words thelines
             thewords

This is how I built the executable:

ghc --make f.hs
ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.1


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



------------------------------

Message: 4
Date: Thu, 4 Apr 2013 22:49:01 -0700
From: Chris Bolton <[email protected]>
Subject: [Haskell-beginners] code review
To: [email protected]
Message-ID:
        <CAA1S5ndxf5=h2vnucsvwxy6snym0lnsp60qbjkbwjdxj2ot...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Just a little code review if anyone has the time :)

http://codereview.stackexchange.com/questions/24741/simple-in-memory-db
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130404/34581676/attachment-0001.htm>

------------------------------

Message: 5
Date: Fri, 5 Apr 2013 16:12:12 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Vertices and Indices
To: "[email protected]" <[email protected]>
Message-ID:
        <cad-ubzhwvavt76vbjzudogamnoacnqp7egf4fx_4uqlwa7a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Folks,

I'm looking at the OpenGL stuff in Haskell and one thing is worrying me.
Doing OpenGL in the past I used to pass an array of vertices to the GPU and
then a list of indices into that array together with a method of joining
them up, e.g. TriangleStrip. In Haskell though, it seems like I'm just
supposed to send a list of vertices and the method, meaning that lots of
vertices get duplicated. Is Haskell doing something clever under the hood
here or is it really that wasteful? Or can I persuade it to use these index
lists?

TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130405/85fc755b/attachment-0001.htm>

------------------------------

Message: 6
Date: Fri, 5 Apr 2013 09:40:05 +0100
From: Tom Davie <[email protected]>
Subject: Re: [Haskell-beginners] Vertices and Indices
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


On 5 Apr 2013, at 09:12, Adrian May <[email protected]> wrote:

> Hi Folks,
> 
> I'm looking at the OpenGL stuff in Haskell and one thing is worrying me. 
> Doing OpenGL in the past I used to pass an array of vertices to the GPU and 
> then a list of indices into that array together with a method of joining them 
> up, e.g. TriangleStrip. In Haskell though, it seems like I'm just supposed to 
> send a list of vertices and the method, meaning that lots of vertices get 
> duplicated. Is Haskell doing something clever under the hood here or is it 
> really that wasteful? Or can I persuade it to use these index lists?

This has nothing to do with Haskell, but instead the fact that someone chose to 
call glDrawArrays instead of glDrawElements.

Thanks

Tom Davie




------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 58, Issue 15
*****************************************

Reply via email to