Currying issues with F#. What is the right way to attach functions to the type?

Viewed 253

I can't understand what is wrong with following bit of code:

let toClass (problem:Problem<'a>) (classID:int) (items:'a list) =
        let newFreqTable = (problem.FreqTables.[classID]).count items
        { problem with FreqTables = newFreqTable :: (problem.FreqTables |> List.filter (fun i -> i.ClassID <> classID)) }
type Problem<'a> when 'a : equality with member this.toClass (classID:int) (items:list<'a>) = toClass this classID items

I have a Problem type which is nothing but a way to group up any number of FreqTables - short for "Frequency tables". So toClass method just takes appropriate freqTable (by classID argument) and returns a new one - with calculated given items.

let typeIndependentCall = toClass p 0 ["word"; "word"; "s"] // this works perfectly

let typeDependentCall = typeIndependentCall.toClass 1 ["word"; "s"] 
// gives an error: "One or more of the overloads of this method has 
// curried arguments. Consider redesigning these members to take 
// arguments in tupled form".

I am pretty new to F# and functional programming. What is the right way to attach behavior to my type?

1 Answers
Related