[Haskell-cafe] Re: Annotating calculations
Chung-chieh Shan
ccshan at post.harvard.edu
Wed Jun 15 14:14:31 EDT 2005
Rene de Visser <rene_de_visser at hotmail.com> wrote in article <BAY2-F447F6436B19F3A687B4D6DAF20 at phx.gbl> in gmane.comp.lang.haskell.cafe:
> I have a somewhat complicated calculation programmed in Haskell.
> This calculation is coded without using monads.
>
> I want to also produce a report describing the details of this calculation
> for each particular set of inputs.
> e.g. Number of hours worked = 100. Gross pay per hour = 50. Total gross =
> 100 * 50 = 500.
> etc.
> But about 20 times more complicated than the above.
I suggest that you consider defining an instance of Num for the type of
a "calculation result annotated with details". A binary operator like +
can then both perform the calculation and combine the annotations. You
probably want an additional operation (outside the Num class) that adds
a new annotation for the current intermediate result. This way, you may
be able to reuse all or most of your calculation code for computing with
and without keeping track of the report.
--
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Mothers are the necessity of invention. --Bill Watterson
More information about the Haskell-Cafe
mailing list