-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleGrades.hs
34 lines (29 loc) · 1.32 KB
/
ExampleGrades.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
{-# LANGUAGE RebindableSyntax #-}
module ExampleSailor where
import Subdistribution
import Prelude hiding ((>>=), (>>), return, Left, Right)
import Data.MultiSet qualified as MSet
data Difficulty = Easy | Hard deriving (Eq, Show, Ord)
data Intelligence = Low | High deriving (Eq, Show, Ord)
data Grade = A | B | C deriving (Eq, Show, Ord)
data SatScore = Bad | Good deriving (Eq, Show, Ord)
data Letter = Positive | Negative deriving (Eq, Show, Ord)
student :: Distribution Intelligence
student = do
diff <- distribution [(Easy, 6/10), (Hard, 4/10)]
intel <- distribution [(Low, 7/10), (High, 3/10)]
grade <- case (intel, diff) of
(Low, Easy) -> distribution [(A, 30/100), (B, 40/100), (C, 30/100)]
(Low, Hard) -> distribution [(A, 5/100), (B, 25/100), (C, 70/100)]
(High, Easy) -> distribution [(A, 90/100), (B, 8/100), (C, 2/100)]
(High, Hard) -> distribution [(A, 50/100), (B, 30/100), (C, 20/100)]
sat <- case intel of
Low -> distribution [(Good, 5/100), (Bad, 95/100)]
High -> distribution [(Good, 80/100), (Bad, 20/100)]
letter <- case grade of
A -> distribution [(Positive, 10/100), (Negative, 90/100)]
B -> distribution [(Positive, 40/100), (Negative, 60/100)]
C -> distribution [(Positive, 99/100), (Negative, 1/100)]
observe (grade == C)
observe (sat == Good)
return intel