[Haskell-cafe] Re: Debugging methods for haskell

wren ng thornton wren at freegeek.org
Sat Jul 18 19:40:41 EDT 2009

Fernan Bolando wrote:
> 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
> calculation
> 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

This would be better as,

data SystemParameterDatabase = SystemParameterDatabase
     { infoSettings  :: InfoSettings
     , statistics    :: Statistics
     , settings      :: Settings
     , nlnr          :: [Matrix Double]
     , timeDependent :: [Matrix Double]

data InfoSettings = InfoSettings
     { pMSET    :: MSET
     , aSetting :: A
     , bSetting :: B

data Statistics = Statistics
     { aStatistic       :: A
     , anotherStatistic :: A
     , bStatistic       :: B

data Settings = Settings
     { temperature :: Kelvin
     , etc         :: Etc

A single-constructor ADT, especially with the labeled-fields syntax, is 
pretty close to C structs; no need to reinvent them and give yourself 

Really, the only thing you should be using lists for is a 
variable-length sequence of elements drawn from the same type and 
distinguished only by their position in the sequence. Whenever the 
length is fixed or the (semantic) type of elements can be distinguished 
from one another (or altered by pushing/popping the list), then a list 
is not what you want to be using because it doesn't capture the 
intention of the type (and therefore allows unintelligible values of the 
type, and inappropriate transformations on the type).

Live well,

More information about the Haskell-Cafe mailing list