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

Add two lists together in OCaml

$
0
0
let rec add_lists (xs : float list) (ys : float list): float list option =  match xs, ys with  | [], [] -> None  | x :: xs, [] -> None  | [], y :: ys -> None  | x :: xs, y :: ys -> (x +. y) :: add_lists xs ys

The question asks us to add the elements of two lists together, if they are different lengths return None. I tried this code, but I get an error message says "This variant expression is expected to have type float list option. There is no constructor :: within type option"Is there any ways to fix it? Thx


Viewing all articles
Browse latest Browse all 598

Latest Images

Trending Articles



Latest Images

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