summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/T8603.hs
blob: d17f246209576b9477e9f8466845a788f9933b5d (plain)
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
module T8603 where

import Control.Monad
import Data.Functor
import Control.Monad.Trans.Class( lift )
import Control.Monad.Trans.State( StateT )

newtype RV a = RV { getPDF :: [(Rational,a)] } deriving (Show, Eq)

instance Functor RV where
  fmap f = RV . map (\(x,y) -> (x, f y)) . getPDF

instance Applicative RV where
  pure = return
  (<*>) = ap

instance Monad RV where
  return x = RV [(1,x)]
  rv >>= f = RV $
    do (p,a) <- getPDF rv
       guard (p > 0)
       (q,b) <- getPDF $ f a
       guard (q > 0)
       return (p*q, b)

type RVState s a = StateT s RV a

uniform :: [a] -> RV a
uniform x = RV [(1/fromIntegral (length x), y) | y <- x]

testRVState1 :: RVState s Bool
testRVState1
  = do prize <- lift uniform [1,2,3]
       return False

-- lift :: (MonadTrans t, Monad m) => m a -> t m a