Personal tools

Num instance for functions

From HaskellWiki

Revision as of 15:24, 13 November 2006 by Lemming (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Some people have argued, that
instances of
would be nice in order

to add functions nicely, say for

f, g :: Num a => b -> a
  you would define
(f+g) x = f x + g x
With an according definition of
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
! :-)

See also