[Haskell-cafe] Re: Debugging methods for haskell

Fernan Bolando fernanbolando at mailc.net
Sat Jul 18 09:23:02 EDT 2009

On Sat, Jul 18, 2009 at 4:57 PM, Jon
Fairbairn<jon.fairbairn at cl.cam.ac.uk> wrote:
> Henning Thielemann <lemming at henning-thielemann.de> writes:
>> On Thu, 16 Jul 2009, Fernan Bolando wrote:
>>> Hi all
>>> I recently used 2 hours of work looking for a bug that was causing
>>> Program error: Prelude.!!: index too large
>> A good way to avoid such problems is to avoid partial
>> functions at all. (!!) is also inefficient. Is it possible
>> to define the function in terms of foldl?
> I've looked at the code a bit more, and, with apologies to the original
> poster, it doesn't look much like Haskell. For example, in
> <http://plan9.bell-labs.com/sources/contrib/fernan/escomma/Circuit.hs>
> there's stuff beginning with
>   tADM :: Int
>   tADM = 1
>   tVSRC :: Int
>   tVSRC = 2
>   tISRC :: Int
>   tISRC = 3
>   ...
> that I think probably should be
>   data Something = ADM | VSRC | ISRC ... deriving (Enum, ...)
> though when I get to "(((fst z0)!!pMSET)!!pMTYPE) == mOP" I'm at a loss
> to determine quite what the intention is. Maybe it should be an array
> indexed by enum types, maybe a function, maybe something that can be
> pattern matched on? I don't know.

The intention is z0 is a system parameter and database, it contains a
set of info needed to define a particular simulation

it looks like ( [n,m...], [m,o,p])

n is is a list info settings for the circuit analysis
m is a list of statistics for the circuits that is need in sub-sequent
m is a list of circuit settings like temperature etc.
o is a list of matrix solution for non-linear newton raphson
p is a list of matrix solution for time dependent calculations

the bug was in o this is a variable length [Double] whose length
depends on the size of
matrix bieng solved.

so. (((fst z0)!!pMSET)!!pMTYPE) == mOP is checking if we are doing mOP
type calculations.
If this was C this would be a structure of settings and buffer data.



More information about the Haskell-Cafe mailing list