Derive functions with interface - F#

Viewed 96

I'm new to F# and I'm trying to implement a little calculator with these interfaces... But I'm struggling with the derive part as soon as i get to f_add.
Would be nice if someone could help me out. :)

type IFunction =
    interface
        abstract member ToString: Unit -> String
        abstract member Apply: Nat -> Nat
        abstract member Derive: Unit -> IFunction
    end
1 Answers

Since f_add is defined in curried form (typical for F# functions), and not tupled, you need to pass the arguments with spaces, not as a tuple:

//                                     HERE .  Using comma makes that a tuple
// member self.Derive () = f_add(f.Derive (), g.Derive ()) //wrong

Instead, pass as an F# style function:

member self.Derive () = f_add (f.Derive ()) (g.Derive ()) 

The same issue exists in the other implementations.

Related