(* 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).
*)
Code output:
>
module Data = begin
type 'a Sensitive = | Sensitive of 'a
type 'a Register = private | Data of 'a list
val sensitive : arg0:'a -> 'a Sensitive
val init : unit -> 'a Register
val add : x:'a -> 'a Register -> 'a Register when 'a : equality
val count : cond:('a -> bool) -> 'a Register -> int
val get : dto:('a -> 'b) -> cond:('a -> bool) -> 'a Register -> 'b option
end
module Random = begin
val private r : System.Random
val next : unit -> int
end
type FooBar =
{foo: int;
bar: int Data.Sensitive;}
val uids : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
val data : FooBar Data.Register
val user1 : int option = Some 235432072
val user2 : int option = Some 235432072