imp-ppl-0.1.0.0: src/Imp/Examples/Knightian.hs
{-# LANGUAGE QualifiedDo, RebindableSyntax #-}
-- | Knightian names controlling correlation between choices.
module Imp.Examples.Knightian
( Three(..)
, dependent
, independent
) where
import Imp
-- | Three-valued outcome.
data Three = Red | Green | Blue
deriving stock (Eq, Ord, Show)
-- | Dependent Knightian choices. Both branches share the same
-- Knightian variable, so the outcomes are correlated.
dependent :: Imp '["a1"] Three
dependent = Imp.do
x <- flip 0.5
if x then Imp.do
y <- knight @"a1"
Imp.return (if y then Red else Green)
else Imp.do
y <- knight @"a1"
Imp.return (if y then Red else Blue)
-- | Independent Knightian choices. Both branches have different
-- Knightian variables, so more outcomes are possible.
independent :: Imp '["a1", "a2"] Three
independent = Imp.do
x <- flip 0.5
if x then Imp.do
y <- knight @"a1"
Imp.return (if y then Red else Green)
else Imp.do
y <- knight @"a2"
Imp.return (if y then Red else Blue)