[Haskell-cafe] was: Debugging methods for haskell structured data types the right way in haskell

Fernan Bolando fernanbolando at mailc.net
Sat Jul 18 21:32:29 EDT 2009


On Sun, Jul 19, 2009 at 7:40 AM, wren ng thornton<wren at freegeek.org> wrote:
> 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
> headaches.
>
>
> 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,
> ~wren

This is the kind of code recommendations I was looking.

thanks

-- 
http://www.fernski.com


More information about the Haskell-Cafe mailing list