-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleDamascus.hs
40 lines (32 loc) · 1.12 KB
/
ExampleDamascus.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE RebindableSyntax #-}
module ExampleDamascus where
import Subdistribution
import Prelude hiding ((>>=), (>>), return)
deathInDamascus :: Strategy -> Distribution Outcome
deathInDamascus f = do
merchant <- uniform [Fleeing, Staying, Random]
death <- case merchant of
Fleeing -> uniform [Aleppo]
Staying -> uniform [Damascus]
Random -> uniform [Aleppo, Damascus]
coin <- uniform [True, False]
observe (f == merchant)
return $ outcome (flee merchant coin) death
flee :: Strategy -> Bool -> City
flee Fleeing _ = Aleppo
flee Staying _ = Damascus
flee Random True = Aleppo
flee Random False = Damascus
outcome :: City -> City -> Outcome
outcome Aleppo Aleppo = MerchantTravelsAndMeetsDeath
outcome Aleppo Damascus = MerchantTravelsAndEscapes
outcome Damascus Aleppo = MerchantEscapes
outcome Damascus Damascus = MerchantMeetsDeath
data Strategy = Fleeing | Staying | Random deriving (Eq, Show)
data City = Damascus | Aleppo deriving (Eq,Show)
data Outcome =
MerchantTravelsAndMeetsDeath
| MerchantTravelsAndEscapes
| MerchantEscapes
| MerchantMeetsDeath
deriving (Eq, Show)