No, there isn't.

> foo = bar;;

C:\...: error FS0001: The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type

It appears that determining function eqality should be possible with these simple functions, but genuine function equality would have to work on arbitrary functions,

eg.

1
2
3
4
let foo x = (x + 1.0)**2.0


let bar x = x**2.0 + 2.0*x + 1.0

We can use algebra to prove that foo = bar, but F# can't do that.

By on 3/8/2010 4:48 PM ()

No, there isn't.

> foo = bar;;

C:\...: error FS0001: The type '('a -> 'a)' does not support the 'equality' constraint because it is a function type

It appears that determining function eqality should be possible with these simple functions, but genuine function equality would have to work on arbitrary functions,

eg.

1
2
let foo x = (x + 1.0)**2.0 
let bar x = x**2.0 + 2.0*x + 1.0

We can use algebra to prove that foo = bar, but F# can't do that.

In continuous domains these aere equivalent functions. In the discrete domain of 'float's, they are not:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let foo x = (x + 1.0)**2.0 
let bar x = x**2.0 + 2.0*x + 1.0

let z1 = 0.0

let z2 = 1.0

let z3 = 1.0 - 1e-16

foo z1 = bar z1

//(true)

foo z2 = bar z2

//(true)

foo z3 = bar z3

//(false)
By on 3/10/2010 6:15 AM ()

Good point, and thanks for the counter example (foo z3 <> bar z3).

I started with the algebraic equation (x +1)^2 = x^2 + 2x + 1, and got caught by the power operator (**) only working on floats. As you point out, with floats the equation no longer holds.

By on 3/10/2010 3:00 PM ()

You can get LIMITED support with quotations:

1
2
3
4
5
6
7
8
        let foo x = <@ x * abs x @>
        let bar x = <@ x * abs x @>
        let x = 2
        let e1 = foo x
        let e2 = bar x

> e1 = e2;;
val it : bool = true

But not all things that should intuitively work will, for example, if you have variables (function objects) in the expression.

By on 3/9/2010 4:24 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper