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

What is Some in OCaml

$
0
0

This Ocaml code traverses a list and outputs the last element.

I dont understand the second condition where we output Some x

let rec last = function | [] -> None | x::[] -> Some x| _ :: t -> last t ;;
  • So if the list is empty we return null.
  • If x is the last element we return Some x (* what is Some x in this context? *)
  • If x is not the last element we go further in the list.

Viewing all articles
Browse latest Browse all 531

Trending Articles



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