summaryrefslogtreecommitdiff
path: root/testsuite/tests/rebindable/rebindable7.hs
blob: 8e0000e0e5706787c65f633422f11fc7aa54c719 (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
37
38
{-# OPTIONS -XRebindableSyntax #-}

-- This one tests rebindable syntax for do-notation

module Main where

import qualified Prelude
import GHC.Num
import GHC.Base hiding( Monad(..) )

class Foo a where
  op :: a -> a

data T a = MkT a 

instance Foo Int where
  op x = x+1

(>>=) :: Foo a => T a -> (a -> T b) -> T b
(>>=) (MkT x) f = f (op x)

(>>) :: Foo a => T a -> T b -> T b
(>>) x y = x >>= (\_ -> y)

return :: Num a => a -> T a
return x = MkT (x+1)

fail :: String -> T a
fail s = error "urk"

t1 :: T Int
t1 = MkT 4

myt = do { x <- t1
	 ; return x }

main = case myt of
	 MkT i -> Prelude.print i