Commit 5cf7fa2d authored by simonpj's avatar simonpj
Browse files

[project @ 2002-11-18 14:18:46 by simonpj]

Add tests for classes operations with a context but no for-all
parent 4c2e9dc1
{-# OPTIONS -fglasgow-exts #-}
-- Similar to tc024, but cross module
module TcRun025_B where
import List( sort )
-- This class has no tyvars in its class op context
-- One uses a newtype, the other a data type
class C1 a where
fc1 :: (?p :: String) => a;
class C2 a where
fc2 :: (?p :: String) => a;
opc :: a
instance C1 String where
fc1 = ?p;
instance C2 String where
fc2 = ?p;
opc = "x"
-- This class constrains no new type variables in
-- its class op context
class D1 a where
fd1 :: (Ord a) => [a] -> [a]
class D2 a where
fd2 :: (Ord a) => [a] -> [a]
opd :: a
instance D1 (Maybe a) where
fd1 xs = sort xs
instance D2 (Maybe a) where
fd2 xs = sort xs
opd = Nothing
......@@ -25,3 +25,6 @@ test('tcrun019', normal, compile_and_run, [''])
test('tcrun020', normal, compile_and_run, [''])
test('tcrun021', normal, compile_and_run, ['-package data'])
test('tcrun022', normal, compile_and_run, ['-O -fglasgow-exts'])
test('tcrun023', normal, compile_and_run, ['-O'])
test('tcrun024', normal, compile_and_run, ['-O'])
test('tcrun025', normal, multimod_compile_and_run, ['tcrun025',''])
{-# OPTIONS -fglasgow-exts #-}
-- Implicit parameters should not give rise to ambiguity.
module Main (main) where
foo :: (?x :: [a]) => Int -> String
foo n = show (n + length ?x)
main = do { putStrLn (let ?x = [True,False] in foo 3) ;
putStrLn (let ?x = "fred" in foo 4) }
{-# OPTIONS -fglasgow-exts #-}
-- Class ops that bind no new type variables
module Main where
import List( sort )
just = [Just "fred",Just "bill"]
main = do { putStrLn (let ?p = "ok1" in fc1);
putStrLn (let ?p = "ok2" in fc2);
putStrLn (show (fd1 just)) ;
putStrLn (show (fd2 just)) }
-- This class has no tyvars in its class op context
-- One uses a newtype, the other a data type
class C1 a where
fc1 :: (?p :: String) => a;
class C2 a where
fc2 :: (?p :: String) => a;
opc :: a
instance C1 String where
fc1 = ?p;
instance C2 String where
fc2 = ?p;
opc = "x"
-- This class constrains no new type variables in
-- its class op context
class D1 a where
fd1 :: (Ord a) => [a] -> [a]
class D2 a where
fd2 :: (Ord a) => [a] -> [a]
opd :: a
instance D1 (Maybe a) where
fd1 xs = sort xs
instance D2 (Maybe a) where
fd2 xs = sort xs
opd = Nothing
ok1
ok2
[Just "bill",Just "fred"]
[Just "bill",Just "fred"]
{-# OPTIONS -fglasgow-exts #-}
-- Like tcrun024, but cross module
module Main where
import TcRun025_B
just = [Just "fred",Just "bill"]
main = do { putStrLn (let ?p = "ok1" in fc1);
putStrLn (let ?p = "ok2" in fc2);
putStrLn (show (fd1 just)) ;
putStrLn (show (fd2 just)) }
ok1
ok2
[Just "bill",Just "fred"]
[Just "bill",Just "fred"]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment