[Haskell-cafe] Hit a wall with the type system

Luke Palmer lrpalmer at gmail.com
Wed Nov 28 23:31:17 EST 2007


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.
>
> 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.

Luke


More information about the Haskell-Cafe mailing list