Ooh. I don't know OCaml, but that looks interesting. I guess I could probably implement something similar in Haskell.
Exactly the same principle in Haskell:
import qualified Data.Map.Strict as Map
data PersonInfo = Name String | Age Integer
m = Map.fromList [("name", Name "Baby Yoda"), ("age", Age 50)]
Map.lookup "name" m
Just (Name name) = Map.lookup "name" m
-- => "Baby Yoda"
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.