[Haskell-cafe] Re: Numeric type classes
dagit at eecs.oregonstate.edu
Wed Sep 13 01:57:42 EDT 2006
On 9/12/06, ajb at spamcop.net <ajb at spamcop.net> wrote:
> G'day all.
> Quoting Henning Thielemann <lemming at henning-thielemann.de>:
> > More precisely: Can you tell me the difference between numbers and "more
> > complex mathematical objects"?
> Yes. A Num is anything which supports the common mathematically-
> significant operations which are supported by the basic built-in machine
> types such as Int and Double. It need not _be_ a built-in machine type,
> but it must support those operations.
And as an example of something which is useful as an instance of num
but isn't a number I have a recent experience I can share.
I was making an embedded domain specific language for excel
spreadsheet formulas recently and found that making my formula
datatype an instance of Num had huge pay offs. You write formulas in
haskell code and then to turn them into something excel can chew on
you only need to show them. I can even use things like Prelude.sum to
add up cells. All I really needed was to define Show and Num
correctly, neither of which took much mental effort or coding tricks.
Now I get tons for free.
More information about the Haskell-Cafe