# Num instance for functions

### From HaskellWiki

(Difference between revisions)

(more Humor than Proposal) |
(Formatting) |
||

Line 2: | Line 2: | ||

to add functions nicely, say for |
to add functions nicely, say for |
||

<haskell>f, g :: Num a => b -> a</haskell> |
<haskell>f, g :: Num a => b -> a</haskell> |
||

− | you would define |
+ | you would define |

<haskell>(f+g) x = f x + g x</haskell> |
<haskell>(f+g) x = f x + g x</haskell> |
||

With an according definition of <hask>fromInteger</hask> |
With an according definition of <hask>fromInteger</hask> |
||

<haskell>fromInteger = const</haskell> |
<haskell>fromInteger = const</haskell> |
||

− | numeric literals would also denote constant functions. This allows |
+ | numeric literals would also denote constant functions. This allows |

<haskell>f+2 == \x -> f x + 2</haskell>. |
<haskell>f+2 == \x -> f x + 2</haskell>. |
||

Line 13: | Line 13: | ||

multiplication dot |
multiplication dot |
||

<haskell>2(x+y) :: Integer</haskell> |
<haskell>2(x+y) :: Integer</haskell> |
||

− | will now be parsed by a Haskell compiler to the most obvious meaning |
+ | will now be parsed by a Haskell compiler to the most obvious meaning |

<haskell>2 :: Integer</haskell> |
<haskell>2 :: Integer</haskell> |
||

− | ! :-) |
+ | ! :-) |

## Revision as of 13:10, 17 April 2007

Some people have argued, thatNum

(->)

to add functions nicely, say for

f, g :: Num a => b -> a

you would define

(f+g) x = f x + g x

fromInteger

fromInteger = const

numeric literals would also denote constant functions. This allows

f+2 == \x -> f x + 2

Even nicer, the mathematically established notation of omitting the multiplication dot

2(x+y) :: Integer

will now be parsed by a Haskell compiler to the most obvious meaning

2 :: Integer

! :-)