I've constructed a mutual-recursive type, consisting of more primitive types also defined like follows:
type Title = Title of string;;
type Value = Value of int;;
type Subcol = Collection list
and Collection =
| Col of Title * Value * Subcol
;;
The subcol may or may not be the empty list, but if it isn't, I'd like to sum both the value of the given collection as well as recursive call on Subcol and the Value defs it might contain. To do this I've constructed the following function:
let rec colList = function
| [] -> 0
| _::v::s -> (colList s) + sumVal v
and sumVal = function
| Value v -> v
and col = function
| Col(_,v,[]) -> (sumVal v)
| Col(_,v,s) -> (sumVal v) + (colList s)
;;
I expect the function call colList s in
Col(_,i,s) -> (sumVal i) + (colList s)
to produce an int from a Subcol type, however I get the following error:
error FS0001: Type mismatch. Expecting a Value list but given a Subcol The type 'Value' does not match the type 'Collection'
I want the colList to accept Subcols, not Value lists.
Any help is appreciated, thank you.