From 8bfbd5f1c911bdc3266d08c156bf34de1eb8c759 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 3 Jul 2018 23:44:12 -0400 Subject: - Can now refine random generators. --- stdlib/source/lux/math/random.lux | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index b8db79ccb..28751e125 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -20,6 +20,7 @@ [stack #+ Stack] [row #+ Row] (tree [finger #+ Tree]))) + (type [refinement #+ Refiner Refined]) )) (type: #export #rec PRNG @@ -66,6 +67,18 @@ (wrap sample) (filter pred gen)))) +(def: #export (refine refiner gen) + {#.doc "Retries the generator until the output can be refined."} + (All [t r] (-> (Refiner t r) (Random t) (Random (Refined t r)))) + (do Monad + [sample gen] + (case (refiner sample) + (#.Some refined) + (wrap refined) + + #.None + (refine refiner gen)))) + (def: #export bool (Random Bool) (function (_ prng) -- cgit v1.2.3