Lets say I create a student record object which is a tuple that consists of (studentID,name,midtermScore,finalScore). I can then use pattern matching to create functions that use this object. For example, a function that returns a composite score based on the student record:
fun score (studentID,name,midtermScore,finalScore) =
( 0.4 * (midtermScore) ) + ( 0.6 * (finalScore) )
Now lets say I wanted to create another function which operates on a whole list of these student record objects, this function would take such a list, and return a new list containing the studentID of each record object, and its composite score. For example:
fun scores ( [studentID,name,midtermScore,finalScore] ) =
map(fn x => (studentID,score(x)))
I can also implement this function in other ways syntactically which also use pattern matching, but the problem I'm having is while the code compiles, it never generates the bindings I'm looking for. For example, the above scores function generates these bindings:
val scores = fn : 'a list -> ('b * 'c * real * real) list -> ('a * real) list
Whereas what I'm trying to achieve is this:
val scores = fn : ('a * 'b * real * real) list -> ('a * real) list
I know whats causing this discrepancy is in the way that I'm pattern matching the list of student record objects as a parameter to the scores function.
Could someone explain semantics wise why I'm getting the bindings that I'm getting, and how I would need to modify the scores function in order to generate the desired bindings?
fun scores ( [studentID,name,midtermScore,finalScore] : ('a * 'b * real * real) list)
– user15270287