packages feed

imp-ppl-0.1.0.0: src/Imp/Examples/Ellsberg.hs

{-# LANGUAGE QualifiedDo, RebindableSyntax #-}
-- | The Ellsberg paradox: 30 Red balls, 60 Black or Yellow in unknown proportion.
module Imp.Examples.Ellsberg
  ( Ball(..)
  , ellsberg
  ) where

import Imp

-- | Balls in the urn.
data Ball = Red | Black | Yellow
  deriving stock (Eq, Ord, Show)

-- | Ellsberg's urn.
ellsberg :: Imp '["split"] Ball
ellsberg = Imp.do
  isRed <- flip (1/3)
  isBlack <- interval @"split" 0.0 1.0
  Imp.return $ if isRed then Red
               else (if isBlack then Black else Yellow)