Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2024:l11 [2024/05/20 00:07]
tpruteanu
pp:2024:l11 [2025/05/09 20:59] (current)
ldaniel fix typo at fmap definition
Line 66: Line 66:
 <code haskell> <code haskell>
 instance Functor Foo where instance Functor Foo where
-  fmap f fx = px >>= (\x -> return (f x))+  fmap f fx = fx >>= (\x -> return (f x))
   ​   ​
 instance Applicative Foo where instance Applicative Foo where
Line 208: Line 208:
  
 <code haskell> <code haskell>
-newtype Prob = Prob [(a, Float)] deriving Show+newtype Prob = Prob [(a, Float)] deriving Show
 </​code>​ </​code>​
  
Line 253: Line 253:
  
 coin :: Prob Coin coin :: Prob Coin
-coin = [(Heads, 0.5), (Tails, 0.5)]+coin = Prob [(Heads, 0.5), (Tails, 0.5)]
  
 unfair_coin :: Prob Coin unfair_coin :: Prob Coin
-unfair_coin = [(Heads, 0.6), (Tails, 0.4)]+unfair_coin = Prob [(Heads, 0.6), (Tails, 0.4)]
  
 flip :: Prob [Coin] flip :: Prob [Coin]
Line 271: Line 271:
 die n = undefined die n = undefined
  
--- (die 20) <*> (die 6) -- the probability distribution of rolling a d20 followed by a d6+-- (,) <​$> ​(die 20) <*> (die 6) -- the probability distribution of rolling a d20 followed by a d6
 </​code>​ </​code>​
  
 **11.4.5.** Let's use this framework to solve a M3 problem: "Jo has took a test for a disease. The result of the test is either positive or negative and the test is 95% reliable: in 95% of cases of people who really have the disease, a positive result is returned, and in 95% of cases of people who do not have the disease, a negative result is obtained. 1% of people of Jo’s age and background have the disease. Jo took the test, and the result is positive. What is the probability that Jo has the disease?"​ **11.4.5.** Let's use this framework to solve a M3 problem: "Jo has took a test for a disease. The result of the test is either positive or negative and the test is 95% reliable: in 95% of cases of people who really have the disease, a positive result is returned, and in 95% of cases of people who do not have the disease, a negative result is obtained. 1% of people of Jo’s age and background have the disease. Jo took the test, and the result is positive. What is the probability that Jo has the disease?"​