Just looking at your code, I have no idea what you are trying to achieve so I'm not surprised the compiler is confused! :-)

I suspect you want an inline function:

1
2
3
4
5
6
7
8
> let inline lerp one p x0 x1 =
    (one - p) * x0 + p * x1;;
val inline lerp :
   ^a -> ^b -> ^d -> ^g -> ^h
    when ( ^a or ^b) : (static member ( - ) : ^a * ^b -> ^c) and
         ( ^c or ^d) : (static member ( * ) : ^c * ^d -> ^e) and
         ( ^e or ^f) : (static member ( + ) : ^e * ^f -> ^h) and
         ( ^b or ^g) : (static member ( * ) : ^b * ^g -> ^f)

However, I have found bugs in the F# compiler with respect to exported inline functions so I would not recommend this for production library code. Finally, you might be interested in the linear, cubic and Lagrange polynomial interpolation routines in our F# for Numerics library.

Regards,
Jon Harrop (Flying Frog Consultancy Ltd.)

By on 6/26/2008 4:26 PM ()

Hi there,

In the original code, static member constraints can't be used on type declarations, and are only for inline functions.

Instead I recommend you simply pass the "add" function as a parameter to the type.

1
2
3
4
5
6
#light

type SomethingSimple<'a>(add: ('a -> 'a -> 'a), finalValue, initialValue) = 
    member x.FinalValue  = finalValue 
    member x.InitialValue  = initialValue
    member x.Sum  = add finalValue initialValue

You might also pass an instance of Math.INumeric to provide a richer range of arithmetic operations. Some pre-baked instances are in Microsoft.FSharp.Math.GlobalAssociations.

Jon, we got your report of a problem with inline functions a while back, but we haven't been able to reproit yet. Could you send us a sample? I suspect the problem may have been to do with your use of an early release of a version of F# we sent you for testing? However if there is a bug we'll of course fix it.

Kind regards & thanks

don

By on 6/27/2008 4:50 PM ()
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