summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving/should_compile/drv020.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/deriving/should_compile/drv020.hs')
-rw-r--r--testsuite/tests/deriving/should_compile/drv020.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_compile/drv020.hs b/testsuite/tests/deriving/should_compile/drv020.hs
new file mode 100644
index 0000000000..8794b745e5
--- /dev/null
+++ b/testsuite/tests/deriving/should_compile/drv020.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,
+ FlexibleInstances, GeneralizedNewtypeDeriving #-}
+
+-- Test deriving of a multi-parameter class for
+-- one-argument newtype defined in the same module
+module ShouldSucceed where
+
+-- library stuff
+
+class Monad m => MonadState s m | m -> s where
+ get :: m s
+ put :: s -> m ()
+
+newtype State s a = State {
+ runState :: (s -> (a, s))
+ }
+
+instance Monad (State s) where
+ return a = State $ \s -> (a, s)
+ m >>= k = State $ \s -> let
+ (a, s') = runState m s
+ in runState (k a) s'
+
+instance MonadState s (State s) where
+ get = State $ \s -> (s, s)
+ put s = State $ \_ -> ((), s)
+
+-- test code
+
+newtype Foo a = MkFoo (State Int a)
+ deriving (Monad, MonadState Int)
+
+f :: Foo Int
+f = get