[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Value classes

Subject: Re: [Haskell-cafe] Value classes
From: Henning Thielemann
Date: Thu, 07 Jan 2010 01:43:22 +0100
Mads LindstrÃm schrieb:
Hi

A function inc5

  inc5 :: Float -> Float
  inc5 x = x + 5

can only be a member of a type class A, if we make all functions from
Float -> Float members of type class A. Thus, I assume, that _type_
class is named type class, as membership is decided by types.

However, it makes no sense to say that all functions from Float -> Float
are invertible or continuous. We would want to specifically say that
inc5 is continuous, not all Float -> Float functions. Thus, we could
have another abstraction, lets call it _value_ class, where we could say
that an individual value (function) could be member. We could say
something like:

  class Invertible (f :: a -> a) where
    invert :: f -> (a -> a)

  instance Invertible inc5 where
    invert _ = \x -> x - 5

In many cases this would be too specific. We would like to say, that
applying the first argument to `+` returns an invertible function.
Something like:

  instance Invertible (`+` x) where
    invert (x +) = \y -> y - x

We would properly also like to say, that composing two invertible
functions results in another invertible function. I guess there are many
more examples.
Maybe you could define types like

newtype InvertibleFunction a b = InvertibleFunction (a -> b)
newtype ContinuousFunction a b = ContinuousFunction (a -> b)
or
newtype AttributedFunction attr a b = AttributedFunction a b
where attr can be Invertible, Continuous, or (Invertible, Continuous).
Then you may define a type class that provides a functional inverse, if attr shows invertibility.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>