(* Ported from Haskell snippet *)moduleData=type'aSensitive=Sensitiveof'atype'aRegister=privateDataof'alistletsensitive=Sensitiveletinit:unit->'aRegister=fun()->Data[]letadd:'a->'aRegister->'aRegister=funx(Datareg)->ifList.exists(funy->x=y)regthenDataregelseData(x::reg)letcount:('a->bool)->'aRegister->int=funcond(Datareg)->reg|>List.filtercond|>List.lengthletget:('a->'b)->('a->bool)->'aRegister->'boption=fundtocond(Datareg)->matchList.tryFindcondregwith|Somex->Some(dtox)|None->None(* Sensitive data generator *)moduleRandom=openSystemletprivater=newRandom()letnext()=r.Next()openDataopenRandom(* Some domain type *)typeFooBar={foo:int;bar:intSensitive;}letuids=[1..10]letdata=uids|>List.fold(funax->Data.add{foo=x;bar=Data.sensitive(Random.next())}a)(Data.init())(* Good person *)letuser1:intoption=data|>Data.get(fun{bar=(Sensitivenum)}->num)(funx->x.foo=7)(* Bad person *)letuser2:intoption=letleak:FooBar->unit=fun{foo=uid;bar=(Sensitivenum)}->System.IO.File.WriteAllText("./dataleaks/"+(Random.next()).ToString()+".log",sprintf"(%i,%i)\n"uidnum)data|>Data.get(fun{FooBar.bar=(Sensitivenum)}->num)(funx->leakx;x.foo=7)(*
Ensure to " ... implement appropriate TECHNICAL and organizational measures,
..., which are DESIGNED to implement data-protection principles, ..., in an
effective manner and to integrate the necessary SAFEGUARDS into the processing
in order to meet the requirements of this Regulation and protect the rights of
data subjects" (Article 25(1) EU GDPR).
*)