summaryrefslogtreecommitdiff
path: root/testsuite/tests/rebindable/rebindable7.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/rebindable/rebindable7.hs')
-rw-r--r--testsuite/tests/rebindable/rebindable7.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/testsuite/tests/rebindable/rebindable7.hs b/testsuite/tests/rebindable/rebindable7.hs
new file mode 100644
index 0000000000..8e0000e0e5
--- /dev/null
+++ b/testsuite/tests/rebindable/rebindable7.hs
@@ -0,0 +1,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