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

OCaml - is enumeration over custom union type possible?

$
0
0

Having a disjont union type like this:

type yolo = | A | B | C

Is it possible in OCaml to iterate/enumerate over each possible value of type yolo without prior knowledge of how many/what these values are?

What I want to achieve is a function that takes a type and returns a list with all of its values. For example:

let yolos = extractor yoloval yolos : yolo list = [A; B; C]

(I am looking for a way to implement extractor function from the above snippet)

In F# my goal is achievable with something similar to this:

open Microsoft.FSharp.Reflectiontype yolo =    | A    | B    | Clet yolos = FSharpType.GetUnionCases typeof<yolo>

Viewing all articles
Browse latest Browse all 528

Trending Articles



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