I am trying to figure out how to implement the fold functions on inputs of differing types. As a sample, I'll use the count function for a list (though, I have multiple functions to implement for this).
Assuming an int list input (this should work with any type of list, though), my count function would be
val count = foldr (fn(x:int,y)=>y+1) 0 ;
val count = fn : int list -> int
However, I am attempting to make a count function where the type is
val count = fn : int list * bool list -> int
where the int list is the universe of the set, and the bool determines which values of the universe are in the set. ie, (1,3,5,6),(true,false,false,true) results in a final set of (1,6), which would have a count of 2. My first thought to try this was some form of
val count= foldr (fn(x:(int*bool),y)=>if #2x then y+1 else y ) 0 ;
but this results in a return type of
val count = fn : (int * bool) list -> int
which is not quite what I need. Logically, they are similar, but I am expected to group the two types together in one list each.