Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 528

Trying to get the number of even and odd integers in a list

$
0
0

I am trying to write a recursive function that takes in a list as argument and returns the number of even and odd numbers in tuple (number_of_even, number_of_odd)

let rec countEvenOdd lst e o =  match lst with  | [] -> (e,o) (* Base case: empty list *)  | hd :: tl -> if hd mod 2 = 0 then countEvenOdd tl (e + 1) o else countEvenOdd tl e (o + 1);;countEvenOdd [2;4;5;6;7;8];;

This just gives me the type:

- : int -> int -> int * int = <fun>

Viewing all articles
Browse latest Browse all 528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>