[Haskell-cafe] Hit a wall with the type system
lrpalmer at gmail.com
Wed Nov 28 23:36:25 EST 2007
On Nov 29, 2007 4:31 AM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Nov 29, 2007 4:02 AM, Chris Smith <cdsmith at twu.net> wrote:
> > I was talking to a few people about this on #haskell, and it was
> > suggested I ask here. I should say that I'm playing around here; don't
> > mistake this for an urgent request or a serious problem.
> > Suppose I wanted to implement automatic differentiation of simple
> > functions on real numbers; then I'd take the operations from Num,
> > Fractional, and Floating, and define how to perform them on pairs of
> > values and their differentials, and then I'd write a differentiate
> > function... but finding an appropriate type for that function seems to
> > be a challenge.
Oh, I think I totally missed the point. I missed the word "simple".
I think the problem is that a function of type Num a => a -> a can be any
function whatsoever, it does not have to be a simple combination of operators
(it could, for example, use show, do a string transformation, and then read
the result). So while you can do your AD type, I think a function which
differentiates (Num a => a -> a) is not possible using this approach. You
must resort to numerical methods...
> > We have:
> > 1. Differentiating a function of the most general type (Num a => a -> a)
> > should produce a result of type (Num a => a -> a).
> I don't see why this should be true. Int -> Int is an instance of this type,
> but derivatives require limits, which integers don't have. Do you intend to
> output the difference sequence of the function in this case?
> But then Double -> Double is also an instance of this type. Do you intend
> to approximate the real derivative when it's specialized to this?
> Instead of worrying about the types, first tell us what semantics you want.
More information about the Haskell-Cafe