[Haskell-cafe] Language extensions
Tomasz Zielonka
tomasz.zielonka at gmail.com
Wed May 30 09:06:42 EDT 2007
On Wed, May 30, 2007 at 02:35:38PM +0200, Henning Thielemann wrote:
>
> On Tue, 29 May 2007, Andrew Coppin wrote:
>
> > OTOH, how many function can you write with :: [Int] -> Int? I can think
> > of a few...
>
> You will probably more like to implement functions like
> Ord a => [a] -> a
> Num a => [a] -> a
> and those generalized signatures tell you more. :-)
Nice observation! Let's see what these types guarantee...
In the Ord variant, the result value pretty much has to come from the
input list or be bottom. It has to be bottom for the empty list. If
f :: Ord a => [a] -> a and g preserves order (is monotonic) then
f (map g l) == g (f l)
This could be nice for testing Ord instances. Unfortunately, for bounded
types the only order preserving function is id.
In Num variant, the result for the empty list with be an integer (or
bottom), no matter what type is 'a'.
All this assuming 'a' has sane Num and Ord instances.
More ideas?
Best regards
Tomek
More information about the Haskell-Cafe
mailing list