{-# LANGUAGE GADTs, ScopedTypeVariables #-}
--- Supplied by Henrik Nilsson, showed up a bug in GADTs
+-- Supplied by Henrik Nilsson, showed up a bug in GADTs
module Nilsson where
usrErr :: String -> String -> String -> a
usrErr = undefined
-type DTime = Double -- [s]
+type DTime = Double -- [s]
data SF a b = SF {sfTF :: a -> Transition a b}
sfId :: SF' a a
sfId = sf
where
- sf = SFArr (\_ a -> (sf, a)) FDI
+ sf = SFArr (\_ a -> (sf, a)) FDI
sfConst :: b -> SF' a b
sfConst b = sf
where
- sf = SFArr (\_ _ -> (sf, b)) (FDC b)
+ sf = SFArr (\_ _ -> (sf, b)) (FDC b)
sfNever :: SF' a (Event b)
sfArrG :: (a -> b) -> SF' a b
sfArrG f = sf
where
- sf = SFArr (\_ a -> (sf, f a)) (FDG f)
+ sf = SFArr (\_ a -> (sf, f a)) (FDG f)
sfAcc :: (c -> a -> (c, b)) -> c -> b -> SF' (Event a) b
-- * We still want to be able to get hold of the original function.
data FunDesc a b where
- FDI :: FunDesc a a -- Identity function
- FDC :: b -> FunDesc a b -- Constant function
- FDE :: (Event a -> b) -> b -> FunDesc (Event a) b -- Event-processing fun
- FDG :: (a -> b) -> FunDesc a b -- General function
+ FDI :: FunDesc a a -- Identity function
+ FDC :: b -> FunDesc a b -- Constant function
+ FDE :: (Event a -> b) -> b -> FunDesc (Event a) b -- Event-processing fun
+ FDG :: (a -> b) -> FunDesc a b -- General function
fdFun :: FunDesc a b -> (a -> b)
fdFun FDI = id
vfyNoEv NoEvent b = b
vfyNoEv _ _ = usrErr "AFRP" "vfyNoEv"
"Assertion failed: Functions on events must not \
- \map NoEvent to Event."
+ \map NoEvent to Event."
compPrim :: SF a b -> SF b c -> SF a c
compPrim (SF {sfTF = tf10}) (SF {sfTF = tf20}) = SF {sfTF = tf0}
where
- tf0 a0 = (cpXX sf1 sf2, c0)
- where
- (sf1, b0) = tf10 a0
- (sf2, c0) = tf20 b0
+ tf0 a0 = (cpXX sf1 sf2, c0)
+ where
+ (sf1, b0) = tf10 a0
+ (sf2, c0) = tf20 b0
- -- Naming convention: cp<X><Y> where <X> and <Y> is one of:
+ -- Naming convention: cp<X><Y> where <X> and <Y> is one of:
-- X - arbitrary signal function
-- A - arbitrary pure arrow
-- C - constant arrow
cpXX sf1 (SFArr _ fd2) = cpXA sf1 fd2
cpXX (SFAcc _ f1 s1 bne) (SFAcc _ f2 s2 cne) =
sfAcc f (s1, s2) (vfyNoEv bne cne)
- where
- f (s1, s2) a =
- case f1 s1 a of
- (s1', NoEvent) -> ((s1', s2), cne)
- (s1', Event b) ->
- let (s2', c) = f2 s2 b in ((s1', s2'), c)
+ where
+ f (s1, s2) a =
+ case f1 s1 a of
+ (s1', NoEvent) -> ((s1', s2), cne)
+ (s1', Event b) ->
+ let (s2', c) = f2 s2 b in ((s1', s2'), c)
cpXX (SFCpAXA _ fd11 sf12 fd13) (SFCpAXA _ fd21 sf22 fd23) =
cpAXA fd11 (cpXX (cpXA sf12 (fdComp fd13 fd21)) sf22) fd23
- cpXX sf1 sf2 = SF' tf
- where
- tf dt a = (cpXX sf1' sf2', c)
- where
- (sf1', b) = (sfTF' sf1) dt a
- (sf2', c) = (sfTF' sf2) dt b
+ cpXX sf1 sf2 = SF' tf
+ where
+ tf dt a = (cpXX sf1' sf2', c)
+ where
+ (sf1', b) = (sfTF' sf1) dt a
+ (sf2', c) = (sfTF' sf2) dt b
cpAXA :: FunDesc a b -> SF' b c -> FunDesc c d -> SF' a d
cpAXA FDI sf2 fd3 = cpXA sf2 fd3
cpAXA fd1 sf2 FDI = cpAX fd1 sf2
cpAXA (FDC b) sf2 fd3 = cpCXA b sf2 fd3
- cpAXA fd1 sf2 (FDC d) = sfConst d
+ cpAXA fd1 sf2 (FDC d) = sfConst d
cpAXA fd1 (SFArr _ fd2) fd3 = sfArr (fdComp (fdComp fd1 fd2) fd3)
- cpAX :: FunDesc a b -> SF' b c -> SF' a c
+ cpAX :: FunDesc a b -> SF' b c -> SF' a c
cpAX FDI sf2 = sf2
cpAX (FDC b) sf2 = cpCX b sf2
cpAX (FDE f1 f1ne) sf2 = cpEX f1 f1ne sf2
cpAX (FDG f1) sf2 = cpGX f1 sf2
- cpXA :: SF' a b -> FunDesc b c -> SF' a c
+ cpXA :: SF' a b -> FunDesc b c -> SF' a c
cpXA sf1 FDI = sf1
cpXA sf1 (FDC c) = sfConst c
cpXA sf1 (FDE f2 f2ne) = cpXE sf1 f2 f2ne
cpCX b (SFAcc _ _ _ cne) = sfConst (vfyNoEv b cne)
cpCX b (SFCpAXA _ fd21 sf22 fd23) =
cpCXA ((fdFun fd21) b) sf22 fd23
- cpCX b sf2 = SFCpAXA tf (FDC b) sf2 FDI
- where
- tf dt _ = (cpCX b sf2', c)
- where
- (sf2', c) = (sfTF' sf2) dt b
+ cpCX b sf2 = SFCpAXA tf (FDC b) sf2 FDI
+ where
+ tf dt _ = (cpCX b sf2', c)
+ where
+ (sf2', c) = (sfTF' sf2) dt b
--- For SPJ: The following version did not work.
+-- For SPJ: The following version did not work.
-- The commented out one below did work, by lambda-lifting cpCXAux
cpCXA :: b -> SF' b c -> FunDesc c d -> SF' a d
cpCXA b sf2 FDI = cpCX b sf2
where
f3 = fdFun fd3
- cpCXAAux :: SF' b c -> SF' a d
+ cpCXAAux :: SF' b c -> SF' a d
cpCXAAux (SFArr _ fd2) = sfConst (f3 ((fdFun fd2) b))
cpCXAAux (SFAcc _ _ _ cne) = sfConst (vfyNoEv b (f3 cne))
cpCXAAux (SFCpAXA _ fd21 sf22 fd23) = cpCXA ((fdFun fd21) b) sf22 (fdComp fd23 fd3)
cpCXA b sf2 fd3 = cpCXAAux b fd3 (fdFun fd3) sf2
where
-- f3 = fdFun fd3
- -- Really something like: cpCXAAux :: SF' b c -> SF' a d
+ -- Really something like: cpCXAAux :: SF' b c -> SF' a d
cpCXAAux :: b -> FunDesc c d -> (c -> d) -> SF' b c -> SF' a d
cpCXAAux b fd3 f3 (SFArr _ fd2) = sfConst (f3 ((fdFun fd2) b))
cpCXAAux b fd3 f3 (SFAcc _ _ _ cne) = sfConst (vfyNoEv b (f3 cne))
-}
cpGX :: (a -> b) -> SF' b c -> SF' a c
- cpGX f1 (SFArr _ fd2) = sfArr (fdComp (FDG f1) fd2)
+ cpGX f1 (SFArr _ fd2) = sfArr (fdComp (FDG f1) fd2)
cpGX f1 (SFCpAXA _ fd21 sf22 fd23) =
cpAXA (fdComp (FDG f1) fd21) sf22 fd23
- cpGX f1 sf2 = SFCpAXA tf (FDG f1) sf2 FDI
- where
- tf dt a = (cpGX f1 sf2', c)
- where
- (sf2', c) = (sfTF' sf2) dt (f1 a)
+ cpGX f1 sf2 = SFCpAXA tf (FDG f1) sf2 FDI
+ where
+ tf dt a = (cpGX f1 sf2', c)
+ where
+ (sf2', c) = (sfTF' sf2) dt (f1 a)
cpXG :: SF' a b -> (b -> c) -> SF' a c
- cpXG (SFArr _ fd1) f2 = sfArr (fdComp fd1 (FDG f2))
+ cpXG (SFArr _ fd1) f2 = sfArr (fdComp fd1 (FDG f2))
cpXG (SFAcc _ f1 s bne) f2 = sfAcc f s (f2 bne)
where
f s a = let (s', b) = f1 s a in (s', f2 b)
- cpXG (SFCpAXA _ fd11 sf12 fd22) f2 =
+ cpXG (SFCpAXA _ fd11 sf12 fd22) f2 =
cpAXA fd11 sf12 (fdComp fd22 (FDG f2))
- cpXG sf1 f2 = SFCpAXA tf FDI sf1 (FDG f2)
- where
- tf dt a = (cpXG sf1' f2, f2 b)
- where
- (sf1', b) = (sfTF' sf1) dt a
+ cpXG sf1 f2 = SFCpAXA tf FDI sf1 (FDG f2)
+ where
+ tf dt a = (cpXG sf1' f2, f2 b)
+ where
+ (sf1', b) = (sfTF' sf1) dt a
cpEX :: (Event a -> b) -> b -> SF' b c -> SF' (Event a) c
- cpEX f1 f1ne (SFArr _ fd2) = sfArr (fdComp (FDE f1 f1ne) fd2)
- cpEX f1 f1ne (SFAcc _ f2 s cne) = sfAcc f s (vfyNoEv f1ne cne)
+ cpEX f1 f1ne (SFArr _ fd2) = sfArr (fdComp (FDE f1 f1ne) fd2)
+ cpEX f1 f1ne (SFAcc _ f2 s cne) = sfAcc f s (vfyNoEv f1ne cne)
where
f s a = f2 s (fromEvent (f1 (Event a)))
- cpEX f1 f1ne (SFCpAXA _ fd21 sf22 fd23) =
+ cpEX f1 f1ne (SFCpAXA _ fd21 sf22 fd23) =
cpAXA (fdComp (FDE f1 f1ne) fd21) sf22 fd23
- cpEX f1 f1ne sf2 = SFCpAXA tf (FDE f1 f1ne) sf2 FDI
- where
- tf dt ea = (cpEX f1 f1ne sf2', c)
- where
+ cpEX f1 f1ne sf2 = SFCpAXA tf (FDE f1 f1ne) sf2 FDI
+ where
+ tf dt ea = (cpEX f1 f1ne sf2', c)
+ where
(sf2', c) = case ea of
- NoEvent -> (sfTF' sf2) dt f1ne
- _ -> (sfTF' sf2) dt (f1 ea)
+ NoEvent -> (sfTF' sf2) dt f1ne
+ _ -> (sfTF' sf2) dt (f1 ea)
- cpXE :: SF' a (Event b) -> (Event b -> c) -> c -> SF' a c
+ cpXE :: SF' a (Event b) -> (Event b -> c) -> c -> SF' a c
cpXE (SFArr _ fd1) f2 f2ne = sfArr (fdComp fd1 (FDE f2 f2ne))
cpXE (SFAcc _ f1 s bne) f2 f2ne = sfAcc f s (vfyNoEv bne f2ne)
where
case eb of NoEvent -> (s', f2ne); _ -> (s', f2 eb)
cpXE (SFCpAXA _ fd11 sf12 fd13) f2 f2ne =
cpAXA fd11 sf12 (fdComp fd13 (FDE f2 f2ne))
- cpXE sf1 f2 f2ne = SFCpAXA tf FDI sf1 (FDE f2 f2ne)
- where
- tf dt a = (cpXE sf1' f2 f2ne,
+ cpXE sf1 f2 f2ne = SFCpAXA tf FDI sf1 (FDE f2 f2ne)
+ where
+ tf dt a = (cpXE sf1' f2 f2ne,
case eb of NoEvent -> f2ne; _ -> f2 eb)
- where
+ where
(sf1', eb) = (sfTF' sf1) dt a
instance (Key a, Key b) => Key (a,b) where
type Map (a,b) = MP a b
- lookup (a,b) (m :: Map (a,b) elt)
+ lookup (a,b) (m :: Map (a,b) elt)
= case lookup a m :: Maybe (Map b elt) of
- Just (m2 :: Map b elt) -> lookup b m2 :: Maybe elt
+ Just (m2 :: Map b elt) -> lookup b m2 :: Maybe elt
data MP a b elt = MP (Map a (Map b elt))
class Eval g env h v where
eval :: env -> g env h v -> v
-evalAbs :: Eval g2 (a2, env) h2 v2
- => env
- -> Abs env (g2 (a2, env) h2 v2) (a2->v2)
- -> (a2->v2)
-evalAbs env (Abs e) x
+evalAbs :: Eval g2 (a2, env) h2 v2
+ => env
+ -> Abs env (g2 (a2, env) h2 v2) (a2->v2)
+ -> (a2->v2)
+evalAbs env (Abs e) x
= eval (x, env) e -- e :: g (a,env) h v
g (T n) = LT
main = do print [f (T 0), f (T 1)]
- print [g (T 2), g (T 3), g (T 4)]
+ print [g (T 2), g (T 3), g (T 4)]
module Foo where
data TValue t where
- TList :: [a] -> TValue [a]
+ TList :: [a] -> TValue [a]
instance (Eq b) => Eq (TValue b) where
(==) (TList p) (TList q) = (==) p q
Here's the reasoning (I have done a bit of renaming).
* The TList constructor really has type
- TList :: forall a. forall x. (a~[x]) => [x] -> TValue a
+ TList :: forall a. forall x. (a~[x]) => [x] -> TValue a
* So in the pattern match we have
- (Eq b) available from the instance header
- TList p :: TValue b
- x is a skolem, existentially bound by the pattern
- p :: [x]
- b ~ [x] available from the pattern match
+ (Eq b) available from the instance header
+ TList p :: TValue b
+ x is a skolem, existentially bound by the pattern
+ p :: [x]
+ b ~ [x] available from the pattern match
* On the RHS we find we need (Eq [x]).
* So the constraint problem we have is
- (Eq b, b~[x]) => Eq [x]
+ (Eq b, b~[x]) => Eq [x]
["Given" => "Wanted"]
Can we prove this? From the two given constraints we can see
that we also have Eq [x], and that certainly proves Eq [x].
a => Eq [a] instance to solve the wanted Eq [x]. And now we need Eq
x, which *isn't* a consequence of (Eq b, b~[x]).
--}
\ No newline at end of file
+-}
module Main where
data Term a where
- Lit :: Int -> Term Int
+ Lit :: Int -> Term Int
IsZero :: Term Int -> Term Bool
If :: Term Bool -> Term a -> Term a -> Term a
- Pr :: Term a -> Term b -> Term (a, b)
- Fst :: Term (a, b) -> Term a
- Snd :: Term (a, b) -> Term b
+ Pr :: Term a -> Term b -> Term (a, b)
+ Fst :: Term (a, b) -> Term a
+ Snd :: Term (a, b) -> Term b
eval :: Term v -> v
-eval (Lit n) = n
+eval (Lit n) = n
eval (IsZero t) = eval t == 0
eval (If t1 t2 t3) = if eval t1 then eval t2 else eval t3
eval (Pr t1 t2) = (eval t1, eval t2)
-eval (Fst t) = case (eval t) of { (a,b) -> a }
-eval (Snd t) = case (eval t) of { (a,b) -> b }
+eval (Fst t) = case (eval t) of { (a,b) -> a }
+eval (Snd t) = case (eval t) of { (a,b) -> b }
term = If (IsZero (Lit 1)) (Pr (Lit 2) (Lit 3)) (Pr (Lit 3) (Lit 4))
-main = print (eval term)
\ No newline at end of file
+main = print (eval term)
{-# LANGUAGE GADTs, KindSignatures #-}
-- Test a couple of trivial things:
--- explicit layout
--- trailing semicolons
--- kind signatures
+-- explicit layout
+-- trailing semicolons
+-- kind signatures
module ShouldCompile where
data Expr :: * -> * where {
EInt :: Int -> Expr Int ;
EBool :: Bool -> Expr Bool ;
EIf :: (Expr Bool) -> (Expr a) -> (Expr a) -> Expr a ;
- -- Note trailing semicolon, should be ok
+ -- Note trailing semicolon, should be ok
}
{-# LANGUAGE GADTs, KindSignatures,
MultiParamTypeClasses, FunctionalDependencies #-}
--- Program from Josef Svenningsson
+-- Program from Josef Svenningsson
-- Just a short explanation of the program. It contains
-- some class declarations capturing some definitions from
-- function defining the semantics for lambda terms called
-- 'interp'.
--- Made GHC 6.4 bleat
+-- Made GHC 6.4 bleat
-- Quantified type variable `t' is unified with
-- another quantified type variable `terminal'
-- When trying to generalise the type inferred for `interp'
inRight :: arr b (coprod a b)
ccase :: arr a c -> arr b c -> arr (coprod a b) c
-class ProductCategory prod arr =>
+class ProductCategory prod arr =>
Exponential exp prod arr | arr -> exp where
eval :: arr (prod (exp a b) a) b
curryA :: arr (prod c a) b -> arr c (exp a b)
-class (Exponential exp prod arr, Terminal terminal arr) =>
- CartesianClosed terminal exp prod arr | arr -> terminal exp prod
+class (Exponential exp prod arr, Terminal terminal arr) =>
+ CartesianClosed terminal exp prod arr | arr -> terminal exp prod
data V prod env t where
Z :: V prod (prod env t) t
Unit :: Lambda foo exp prod env foo
Var :: V prod env t -> Lambda terminal exp prod env t
{- Lam :: Lambda terminal exp prod (prod env a) t
- -> Lambda terminal exp prod env (exp a t)
- App :: Lambda terminal exp prod env (exp t t')
- -> Lambda terminal exp prod env t -> Lambda terminal exp prod env t'
+ -> Lambda terminal exp prod env (exp a t)
+ App :: Lambda terminal exp prod env (exp t t')
+ -> Lambda terminal exp prod env t -> Lambda terminal exp prod env t'
-}
-interp :: CartesianClosed terminal exp prod arr =>
- Lambda terminal exp prod s t -> arr s t
+interp :: CartesianClosed terminal exp prod arr =>
+ Lambda terminal exp prod s t -> arr s t
interp (Unit) = terminal -- Terminal terminal arr => arr a terminal
-- interp (Var Z) = second
-- interp (Var (S v)) = first `comp` interp (Var v)
Arr :: Ty a -> Ty b -> Ty (a -> b)
data Exp g t where
- Var :: Var g t -> Exp g t
- Lam :: Ty a -> Exp (g,a) b -> Exp g (a->b)
- App :: Exp g (s -> t) -> Exp g s -> Exp g t
- If :: Exp g Bool -> Exp g t -> Exp g t -> Exp g t
+ Var :: Var g t -> Exp g t
+ Lam :: Ty a -> Exp (g,a) b -> Exp g (a->b)
+ App :: Exp g (s -> t) -> Exp g s -> Exp g t
+ If :: Exp g Bool -> Exp g t -> Exp g t -> Exp g t
ETrue :: Exp g Bool
EFalse :: Exp g Bool
Cons :: Ty t -> TyEnv h -> TyEnv (h,t)
infer :: TyEnv g -> Exp g t -> Ty t
-infer g (Var x) = inferVar g x
-infer g (Lam t e) = Arr t (infer (Cons t g) e)
-infer g (App e e') = case infer g e of Arr _ t -> t
-infer g (ETrue) = Bool
-infer g (EFalse) = Bool
-infer g (If _ e _) = infer g e
+infer g (Var x) = inferVar g x
+infer g (Lam t e) = Arr t (infer (Cons t g) e)
+infer g (App e e') = case infer g e of Arr _ t -> t
+infer g (ETrue) = Bool
+infer g (EFalse) = Bool
+infer g (If _ e _) = infer g e
inferVar :: TyEnv g -> Var g t -> Ty t
inferVar (Cons t h) (SVar x) = inferVar h x
data Tree a = Val a | Choice (Tree a) (Tree a)
-- doesn't yet force trees to be fully balanced:
--- Val :: a -> Tree a Z
--- Choice :: Tree a n -> Tree a n -> Tree a (S n)
+-- Val :: a -> Tree a Z
+-- Choice :: Tree a n -> Tree a n -> Tree a (S n)
instance Functor Tree where
fmap = liftM
-- quote & friends -------------------------------------------------------------
-- for values --------------------------
-enumV :: Ty t -> Tree t
-questionsV :: Ty t -> [t -> Bool]
+enumV :: Ty t -> Tree t
+questionsV :: Ty t -> [t -> Bool]
enumV Bool = Choice (Val True) (Val False)
where
mkEnum [] t = tmap const t
mkEnum (q:qs) es = do
- f1 <- mkEnum qs es
- f2 <- mkEnum qs es
- return (\d -> if q d then f1 d else f2 d)
+ f1 <- mkEnum qs es
+ f2 <- mkEnum qs es
+ return (\d -> if q d then f1 d else f2 d)
-questionsV Bool = return (\x -> x)
-questionsV (Arr s t) = do
- d <- flatten (enumV s)
- q <- questionsV t
- return (\f -> q (f d))
+questionsV Bool = return (\x -> x)
+questionsV (Arr s t) = do
+ d <- flatten (enumV s)
+ q <- questionsV t
+ return (\f -> q (f d))
-- for expressions ---------------------
-enumE :: Ty t -> Tree (Exp g t)
-questionsE :: Ty t -> [Exp g t -> Exp g Bool]
+enumE :: Ty t -> Tree (Exp g t)
+questionsE :: Ty t -> [Exp g t -> Exp g Bool]
enumE Bool = Choice (Val ETrue) (Val EFalse)
enumE (Arr s t) = tmap (lamE s) (mkEnumE (questionsE s) (enumE t))
where
mkEnumE [] t = tmap const t
mkEnumE (q:qs) es = do
- f1 <- mkEnumE qs es
- f2 <- mkEnumE qs es
- return (\d -> ifE (q d) (f1 d) (f2 d))
-
-questionsE Bool = return (\x -> x)
-questionsE (Arr s t) = do
- d <- flatten (enumE s)
- q <- questionsE t
- return (\f -> q (App f d))
-
--- should be
--- find (List (Exp g Bool) n) -> Tree (Exp g a) n -> Exp g a
+ f1 <- mkEnumE qs es
+ f2 <- mkEnumE qs es
+ return (\d -> ifE (q d) (f1 d) (f2 d))
+
+questionsE Bool = return (\x -> x)
+questionsE (Arr s t) = do
+ d <- flatten (enumE s)
+ q <- questionsE t
+ return (\f -> q (App f d))
+
+-- should be
+-- find (List (Exp g Bool) n) -> Tree (Exp g a) n -> Exp g a
find :: [Exp g Bool] -> Tree (Exp g a) -> Exp g a
-find [] (Val a) = a
-find (b:bs) (Choice l r) = ifE b (find bs l) (find bs r)
-find _ _ = error "bad arguments to find"
+find [] (Val a) = a
+find (b:bs) (Choice l r) = ifE b (find bs l) (find bs r)
+find _ _ = error "bad arguments to find"
quote :: Ty t -> t -> Exp g t
quote Bool t = case t of True -> ETrue; False -> EFalse
quote (Arr s t) f = lamE s (\e -> find (do q <- questionsE s; return (q e))
- (tmap (quote t . f) (enumV s)))
+ (tmap (quote t . f) (enumV s)))
-- normalization (by evaluation) -----------------------------------------------
data BoxExp t = Box (forall g. Exp g t)
, eqB (nf b22b twice) (nf b22b once)]
where nf = normalize
-main = print test
\ No newline at end of file
+main = print test
h v = x v + 1
main = do { let t1 = T1 { y = "foo", x = 4 }
- t2 = g t1
- ; print (h (f 8 undefined))
- ; print (h t2)
- }
-
\ No newline at end of file
+ t2 = g t1
+ ; print (h (f 8 undefined))
+ ; print (h t2)
+ }
-- data RBTree = forall n. Root (SubTree Black n)
-- Kind Colour
-data Red
+data Red
data Black
-- Kind Nat
ins :: Int -> SubTree c n -> SubTree c n
-ins n Leaf = (Fix (RNode Leaf n Leaf))
+ins n Leaf = (Fix (RNode Leaf n Leaf))
ins n (BNode x m y) | n <= m = black (ins n x) m y
ins n (BNode x m y) | n > m = black x m (ins n y)
ins n (RNode x m y) | n <= m = RNode (ins n x) m y
ins n (RNode x m y) | n > m = RNode x m (ins n y)
-
+
black :: SubTree c n -> Int -> SubTree d n -> SubTree Black (S n)
black (RNode (Fix u) v c) w (x@(RNode _ _ _)) = Fix(RNode (blacken u) v (BNode c w x))
g3 :: forall x y . D x y -> ()
-- D (..) :: D x y
-- C (..) :: C sk y
--- sk = y
+-- sk = y
-- p :: sk
g3 (D (C (p :: y))) = ()
{-# LANGUAGE GADTs #-}
--- Provoked by
+-- Provoked by
-- http://www.haskell.org/pipermail/haskell-cafe/2007-January/021086.html
module ShouldCompile where
---------------------
data SetM2 a where
SM2 :: Ord w => Teq a w -> Set.Set w -> SetM2 a
- -- Different order of args in Teq
+ -- Different order of args in Teq
unionA2 :: SetM2 a -> SetM2 a -> SetM2 a
unionA2 (SM2 Teq m1) (SM2 Teq m2)
= case p1 of Teq -> case p2 of Teq -> SM2 Teq (m1 `Set.union` m2)
unionC2 :: SetM2 a -> SetM2 a -> SetM2 a
-unionC2 (SM2 p1 m1) (SM2 p2 m2)
+unionC2 (SM2 p1 m1) (SM2 p2 m2)
= case (p1,p2) of (Teq,Teq) -> SM2 Teq (m1 `Set.union` m2)
test4 = NonTerminating (Apply omega omega) help3
help1 :: Reducible (Apply Omega Omega)
-help1 = Reducible (ReduceSimple
- (ReplaceApply (ReplaceVarEq Equal (LiftLambda
- (LiftApply (LiftVarLess LessZero) (LiftVarLess LessZero))))
- (ReplaceVarEq Equal (LiftLambda (LiftApply
- (LiftVarLess LessZero) (LiftVarLess LessZero))))))
+help1 = Reducible (ReduceSimple
+ (ReplaceApply (ReplaceVarEq Equal (LiftLambda
+ (LiftApply (LiftVarLess LessZero) (LiftVarLess LessZero))))
+ (ReplaceVarEq Equal (LiftLambda (LiftApply
+ (LiftVarLess LessZero) (LiftVarLess LessZero))))))
help2 :: ReduceEventually (Apply Omega Omega) t -> Equal (Apply Omega Omega) t
help2 ReduceZero = Equal
-help2 (ReduceSucc (ReduceSimple (ReplaceApply
- (ReplaceVarEq _ (LiftLambda (LiftApply (LiftVarLess _) (LiftVarLess _))))
- (ReplaceVarEq _ (LiftLambda (LiftApply (LiftVarLess _) (LiftVarLess _)))))) y)
+help2 (ReduceSucc (ReduceSimple (ReplaceApply
+ (ReplaceVarEq _ (LiftLambda (LiftApply (LiftVarLess _) (LiftVarLess _))))
+ (ReplaceVarEq _ (LiftLambda (LiftApply (LiftVarLess _) (LiftVarLess _)))))) y)
= case help2 y of
Equal -> Equal
help3 :: Infinite (Apply Omega Omega)
help3 x = case help2 x of
- Equal -> help1
+ Equal -> help1
T1 :: { w :: !(Int, Int), x :: a, y :: b } -> T (a,b)
T2 :: { w :: !(Int, Int), x :: a } -> T (a,b)
T3 :: { z :: Int } -> T Bool
-
+
-- T1 :: forall c a b. (c~(a,b)) => (Int,Int) -> a -> b -> T c
f xv yv = T1 { w = (0,0), x = xv, y = yv }
i v = let (x,y) = w v in x + y
main = do { let t1 = T1 { w = (0,0), y = "foo", x = 4 }
- t2 = g t1
- ; print (h (f 8 undefined))
- ; print (h t2)
+ t2 = g t1
+ ; print (h (f 8 undefined))
+ ; print (h t2)
; print (i t1)
- }
+ }
data V s t where
Z :: V (t,m) t
- S :: V m t -> V (x,m) t
-
+ S :: V m t -> V (x,m) t
+
data Exp s t where
- IntC :: Int -> Exp s Int -- 5
- BoolC :: Bool -> Exp s Bool -- True
- Plus :: Exp s Int -> Exp s Int -> Exp s Int -- x + 3
- Lteq :: Exp s Int -> Exp s Int -> Exp s Bool -- x <= 3
- Var :: V s t -> Exp s t -- x
+ IntC :: Int -> Exp s Int -- 5
+ BoolC :: Bool -> Exp s Bool -- True
+ Plus :: Exp s Int -> Exp s Int -> Exp s Int -- x + 3
+ Lteq :: Exp s Int -> Exp s Int -> Exp s Bool -- x <= 3
+ Var :: V s t -> Exp s t -- x
data Com s where
- Set :: V s t -> Exp s t -> Com s -- x := e
- Seq :: Com s -> Com s -> Com s -- { s1; s2; }
- If :: Exp s Bool -> Com s -> Com s -> Com s -- if e then x else y
- While :: Exp s Bool -> Com s -> Com s -- while e do s
- Declare :: Exp s t -> Com (t,s) -> Com s -- { int x = 5; s }
+ Set :: V s t -> Exp s t -> Com s -- x := e
+ Seq :: Com s -> Com s -> Com s -- { s1; s2; }
+ If :: Exp s Bool -> Com s -> Com s -> Com s -- if e then x else y
+ While :: Exp s Bool -> Com s -> Com s -- while e do s
+ Declare :: Exp s t -> Com (t,s) -> Com s -- { int x = 5; s }
update :: (V s t) -> t -> s -> s
update Z n (x,y) = (n,y)
exec (If test x1 x2) s =
if (eval test s) then exec x1 s else exec x2 s
exec (While test body) s = loop s
- where loop s = if (eval test s)
- then loop (exec body s)
+ where loop s = if (eval test s)
+ then loop (exec body s)
else s
exec (Declare e body) s = store
where (_,store) = (exec body (eval e s,s))
v3 = S (S (S Z))
e2 = Lteq (Plus (Var v0)(Var v1)) (Plus (Var v0) (IntC 1))
-
+
sum_var = Z
x = S Z
prog :: Com (Int,(Int,a))
-prog =
+prog =
Seq (Set sum_var (IntC 0))
(Seq (Set x (IntC 1))
(While (Lteq (Var x) (IntC 5))
(Seq (Set sum_var (Plus (Var sum_var)(Var x)))
(Set x (Plus (Var x) (IntC 1))))))
-
-ans = exec prog (34,(12,1))
+
+ans = exec prog (34,(12,1))
main = print ans
{-
{ sum = 0 ;
{ sum = sum + x;
x = x + 1;
}
-}
+}
-}
data TypeR t where
IntR :: TypeR Int
BoolR :: TypeR Bool
- PairR :: TypeR a -> TypeR b -> TypeR (a,b)
+ PairR :: TypeR a -> TypeR b -> TypeR (a,b)
-- Judgments for Types
-data TJudgment = forall t . TJ (TypeR t)
+data TJudgment = forall t . TJ (TypeR t)
checkT :: TyAst -> TJudgment
checkT I = TJ IntR
checkT B = TJ BoolR
-checkT (P x y) =
+checkT (P x y) =
case (checkT x,checkT y) of
(TJ a, TJ b) -> TJ(PairR a b)
do { EqProof <- match a c
; EqProof <- match b d
; succeed EqProof }
-match _ _ = fail "match fails"
+match _ _ = fail "match fails"
----------------------------------------------
checkV 0 t1 (PairR t2 p) =
do { EqProof <- match t1 t2
; return Z }
-checkV n t1 (PairR ty p) =
+checkV n t1 (PairR ty p) =
do { v <- checkV (n-1) t1 p; return(S v)}
checkV n t1 sr = Nothing
-----------------------------------------------------
-data ExpAst
+data ExpAst
= IntCA Int
| BoolCA Bool
| PlusA ExpAst ExpAst
| VarA Int TyAst
-- Judgments for Expressions
-data EJudgment s = forall t . EJ (TypeR t) (Exp s t)
+data EJudgment s = forall t . EJ (TypeR t) (Exp s t)
checkE :: ExpAst -> TypeR s -> Maybe (EJudgment s)
checkE (IntCA n) sr = succeed(EJ IntR (IntC n))
; EJ t2 e2 <- checkE y sr
; EqProof <- match t2 IntR
; succeed(EJ IntR (Plus e1 e2))}
-checkE (VarA n ty) sr =
+checkE (VarA n ty) sr =
do { TJ t <- succeed(checkT ty)
- ; v <- checkV n t sr
+ ; v <- checkV n t sr
; return(EJ t (Var v)) }
-----------------------------------------------------
-data ComAst
+data ComAst
= SetA Int TyAst ExpAst
| SeqA ComAst ComAst
| IfA ExpAst ComAst ComAst
; EJ t2 e1 <- checkE e sr
; EqProof <- match t1 t2
; return(EC (Set v e1))}
-checkC (SeqA x y) sr =
+checkC (SeqA x y) sr =
do { EC c1 <- checkC x sr
; EC c2 <- checkC y sr
; return(EC (Seq c1 c2)) }
-checkC (IfA e x y) sr =
+checkC (IfA e x y) sr =
do { EJ t1 e1 <- checkE e sr
; EqProof <- match t1 BoolR
; EC c1 <- checkC x sr
; EC c2 <- checkC y sr
; return(EC(If e1 c1 c2)) }
-checkC (WhileA e x) sr =
+checkC (WhileA e x) sr =
do { EJ t1 e1 <- checkE e sr
; EqProof <- match t1 BoolR
; EC c1 <- checkC x sr
; return(EC(While e1 c1)) }
-checkC (DeclareA ty e c) sr =
+checkC (DeclareA ty e c) sr =
do { TJ t1 <- succeed(checkT ty)
; EJ t2 e2 <- checkE e sr
; EqProof <- match t1 t2
e1 = Lteq (Plus (Var sum_var)(Var x)) (Plus (Var x) (IntC 1))
{-
-data Store s
+data Store s
= M (Code s)
| forall a b . N (Code a) (Store b) where s = (a,b)
test e = [| \ (x,(y,z)) -> $(eval2 e (N [|x|] (N [|y|] (M [|z|])))) |]
-- test e1 ---> [| \ (x,(y,z)) -> x + y <= y + 1 |]
--}
\ No newline at end of file
+-}
g i = let a = i + 1
- b = id
+ b = id
c = ()
d = (+)
in (a,b,c,d)
g i = (a,b,c)
where a = False
- b = True
+ b = True
c = ()
g i = let a = False
- b = True
+ b = True
c = (a,b)
in c
-- Test that we can recover unicode DataCons in :print
-data T
- = À -- latin
- | Α -- greek
- | Ⴀ -- georgian
- | Ϣ -- coptic
- | А -- cyrillic
- | Ա -- armenian
+data T
+ = À -- latin
+ | Α -- greek
+ | Ⴀ -- georgian
+ | Ϣ -- coptic
+ | А -- cyrillic
+ | Ա -- armenian
deriving Show
test =
- [ À -- latin
- , Α -- greek
- , Ⴀ -- georgian
- , Ϣ -- coptic
- , А -- cyrillic
- , Ա -- armenian
+ [ À -- latin
+ , Α -- greek
+ , Ⴀ -- georgian
+ , Ϣ -- coptic
+ , А -- cyrillic
+ , Ա -- armenian
]
-- test that we have all the promised instances
module Main(main) where
-
-import Control.Monad.Fix
+
+import Control.Monad.Fix
import qualified Control.Monad.ST as SST
import qualified Control.Monad.ST.Lazy as LST
generic :: MonadFix m => m [Int]
generic = mdo xs <- return (1:xs)
- return (take 4 xs)
+ return (take 4 xs)
io :: IO [Int]
io = generic
lst :: LST.ST s [Int]
lst = generic
-
+
mb :: Maybe [Int]
mb = generic
ls = generic
main :: IO ()
-main = do
- print =<< io
- print $ SST.runST sst
- print $ LST.runST lst
- print $ mb
- print $ ls
+main = do
+ print =<< io
+ print $ SST.runST sst
+ print $ LST.runST lst
+ print $ mb
+ print $ ls
(X a) >>= f = f a
instance MonadFix X where
- mfix f = fix (f . unX)
+ mfix f = fix (f . unX)
where unX ~(X x) = x
z :: X [Int]
z = mdo x <- return (1:x)
- return (take 4 x)
+ return (take 4 x)
main = print z
{-# OPTIONS -XRecursiveDo #-}
--- test let bindings, polymorphism is ok provided they are not
+-- test let bindings, polymorphism is ok provided they are not
-- isolated in a recursive segment
-- NB. this is not what Hugs does!
module Main (main) where
-import Control.Monad.Fix
+import Control.Monad.Fix
t :: IO (Int, Int)
t = mdo let l [] = 0
l (x:xs) = 1 + l xs
- return (l "1", l [1,2,3])
+ return (l "1", l [1,2,3])
main :: IO ()
main = t >>= print
module Main (main) where
-import Control.Monad.Fix
+import Control.Monad.Fix
import Data.Maybe ( fromJust )
t = mdo x <- fromJust (mdo x <- Just (1:x)
- return (take 4 x))
- return x
+ return (take 4 x))
+ return x
main :: IO ()
-main = print t
+main = print t
main :: IO ()
main = mdo x <- return (1:x)
- return ()
+ return ()
import Control.Monad
norm a = mdo (_, sz) <- getBounds a
- s <- ioaA 1 s sz 0
- return ()
- where
- ioaA i s sz acc
- | i > sz = return acc
- | True = do v <- readArray a i
- writeArray a i (v / s)
- ioaA (i+1) s sz $! (v + acc)
+ s <- ioaA 1 s sz 0
+ return ()
+ where
+ ioaA i s sz acc
+ | i > sz = return acc
+ | True = do v <- readArray a i
+ writeArray a i (v / s)
+ ioaA (i+1) s sz $! (v + acc)
toList a = do (_, sz) <- getBounds a
- mapM (\i -> readArray a i) [1..sz]
+ mapM (\i -> readArray a i) [1..sz]
test :: Int -> IO ()
test sz = do
- (arr :: IOArray Int Float) <- newArray (1, sz) 12
- putStrLn "Before: "
- toList arr >>= print
- norm arr
- putStrLn "After: "
- lst <- toList arr
- print lst
- putStrLn ("Normalized sum: " ++ show (sum lst))
+ (arr :: IOArray Int Float) <- newArray (1, sz) 12
+ putStrLn "Before: "
+ toList arr >>= print
+ norm arr
+ putStrLn "After: "
+ lst <- toList arr
+ print lst
+ putStrLn ("Normalized sum: " ++ show (sum lst))
main = test 10
module Mod173_Aux( module Mod173_Aux ) where
import qualified Data.List as Mod173_Aux( nub )
- -- This should not be exported
+ -- This should not be exported
-import Data.List as Mod173_Aux( partition )
- -- This one should be exported
+import Data.List as Mod173_Aux( partition )
+ -- This one should be exported
-frob x = Mod173_Aux.nub (x::[Int]) -- This one should
+frob x = Mod173_Aux.nub (x::[Int]) -- This one should
-- )
module M where
-import Prelude hiding ( negate, enumFrom,
- enumFromThen, enumFromTo,
- enumFromThenTo )
+import Prelude hiding ( negate, enumFrom,
+ enumFromThen, enumFromTo,
+ enumFromThenTo )
import Data.Ix hiding ( rangeSize )
negate = undefined
enumFrom = undefined
module M (module Mod171_A, h) where
-import Mod171_A -- This isn't unused...
-import Mod171_B -- even though this imports all the same stuff
+import Mod171_A -- This isn't unused...
+import Mod171_B -- even though this imports all the same stuff
h :: Int -> Int
h = g
import Mod173_Aux
-t1 = partition -- From the import
+t1 = partition -- From the import
nub = True
-t2 = nub -- Unambiguous; nub should not have been exported
+t2 = nub -- Unambiguous; nub should not have been exported
t3 = frob
-- This test works efficiently because the full laziness
-- pass now floats out applications
--- \x -> f y (x+1)
+-- \x -> f y (x+1)
-- It'll float out the (f y) if that's a redex
loop :: Double -> [Int] -> Double
(note that (^) has arity 2 so the application is oversaturated). Why
doesn't that happen? SetLevels (if this is the right place to look)
has this:
-
--}
\ No newline at end of file
+
+-}
import System.CPUTime
size :: Int
-size = 40000 -- This was big enough to take 5 seconds in
- -- the bad case on my machine.
+size = 40000 -- This was big enough to take 5 seconds in
+ -- the bad case on my machine.
data Any = forall a. (Typeable a) => Any a
module DoParamM where
-import Prelude (const, String, ($), (.), Maybe(..),
- Int, fromInteger, succ, pred, fromEnum, toEnum,
- (+), Char, (==), Bool(..),
- IO, getLine, putStrLn, read, show)
+import Prelude (const, String, ($), (.), Maybe(..),
+ Int, fromInteger, succ, pred, fromEnum, toEnum,
+ (+), Char, (==), Bool(..),
+ IO, getLine, putStrLn, read, show)
import qualified Prelude
import qualified Control.Monad.State as State
import qualified Control.Monad.Identity as IdM
fail = RegularM . Prelude.fail
m >>= f = RegularM ((Prelude.>>=) (unRM m) (unRM . f))
--- As a warm-up, we write the regular State computation, with the same
+-- As a warm-up, we write the regular State computation, with the same
-- type of state throughout. We thus inject Monad.State into the
-- parameterized monad
-- The same in the do-notation
test1_do = State.runState (unRM c) (0::Int) where
c = do
- v <- gget
- gput (succ v)
- return v
+ v <- gget
+ gput (succ v)
+ return v
gget :: (State.MonadState s m) => RegularM m s s s
gget = RegularM State.get
gput :: (State.MonadState s m) => s -> RegularM m s s ()
instance Prelude.Monad m => Monadish (VST m) where
return x = VST (\si -> Prelude.return (si,x))
fail x = VST (\si -> Prelude.fail x)
- m >>= f = VST (\si -> (Prelude.>>=) (runVST m si)
- (\ (sm,x) -> runVST (f x) sm))
+ m >>= f = VST (\si -> (Prelude.>>=) (runVST m si)
+ (\ (sm,x) -> runVST (f x) sm))
vsget :: Prelude.Monad m => VST m si si si
vsget = VST (\si -> Prelude.return (si,si))
-- The same with the do-notation
vsm1_do () = do
- v <- vsget
- vsput (succ v)
- return v
+ v <- vsget
+ vsput (succ v)
+ return v
{-
*DoParamM> :t vsm1
-- Now, we vary the type of the state, from Int to a Char
-vsm2 () = vsget >>= (\v -> vsput ((toEnum (65+v))::Char) >>
+vsm2 () = vsget >>= (\v -> vsput ((toEnum (65+v))::Char) >>
vsget >>= \v' -> return (v,v'))
{-
-- The same with the do-notation
-- the following does not yet work
vsm2_do () = do
- v <- vsget
+ v <- vsget
vsput ((toEnum (65+v))::Char)
v' <- vsget
- return (v,v')
+ return (v,v')
test3 = IdM.runIdentity (runVST (vsm2 ()) (0::Int))
-- ('A',(0,'A'))
In the first argument of `return', namely `(v == v')'
In the expression: return (v == v')
-vsm3 () = vsget >>= (\v -> vsput ((toEnum (65+v))::Char) >>
+vsm3 () = vsget >>= (\v -> vsput ((toEnum (65+v))::Char) >>
vsget >>= \v' -> return (v==v'))
-}
-- The following too must report a type error -- the expression
-- return (v == v') must be flagged, rather than something else
vsm3_do () = do
- v <- vsget
+ v <- vsget
vsput ((toEnum (65+v))::Char)
v' <- vsget
- return (v==v')
+ return (v==v')
crec1 = vsget >>= (\s1 -> case fromEnum s1 of
0 -> return 0
1 -> vsput (pred s1) >> return 1
- _ -> vsput True >>
+ _ -> vsput True >>
crec1 >>= (\v ->
(vsput s1 >> -- restore state type to si
return (v + 10))))
-- The same in the do-notation
crec1_do :: (Prelude.Enum si, Prelude.Monad m) => VST m si si Int
crec1_do = do
- s1 <- vsget
+ s1 <- vsget
case fromEnum s1 of
0 -> return 0
1 -> do {vsput (pred s1); return 1}
_ -> do
- vsput True
+ vsput True
v <- crec1_do
vsput s1 -- restore state type to si
return (v + 10)
-- User code
-tlock1 = lget >>= (\l ->
- return (read l) >>= (\x ->
- lput (show (x+1))))
+tlock1 = lget >>= (\l ->
+ return (read l) >>= (\x ->
+ lput (show (x+1))))
tlock1r = runLIO tlock1
-- the same in the do-notation
tlock1_do = do
- l <- lget
- let x = read l
- lput (show (x+1))
+ l <- lget
+ let x = read l
+ lput (show (x+1))
{-
*VarStateM> :t tlock1
-}
-tlock2 = lget >>= (\l ->
- lock >> (
- return (read l) >>= (\x ->
- lput (show (x+1)))))
+tlock2 = lget >>= (\l ->
+ lock >> (
+ return (read l) >>= (\x ->
+ lput (show (x+1)))))
tlock2_do = do
- l <- lget
- lock
- let x = read l
- lput (show (x+1))
+ l <- lget
+ lock
+ let x = read l
+ lput (show (x+1))
{-
*VarStateM> :t tlock2
{-
gives a type error:
Couldn't match expected type `Locked'
- against inferred type `Unlocked'
+ against inferred type `Unlocked'
Expected type: LIO Locked r b
Inferred type: LIO Unlocked Locked ()
In the expression: tlock2
{-
DoParamM.hs:298:30:
Couldn't match expected type `Unlocked'
- against inferred type `Locked'
+ against inferred type `Locked'
Expected type: LIO Unlocked r b
Inferred type: LIO Locked Unlocked ()
In the second argument of `(>>)', namely `unlock'
import Prelude hiding ( id, (.) )
-import Control.Category ( Category(..) )
+import Control.Category ( Category(..) )
import Control.Arrow
garbage x =
{-# LANGUAGE RebindableSyntax, NPlusKPatterns #-}
module RebindableCase1 where
- {
--- import Prelude;
- import Prelude(String,undefined,Maybe(..), (==), (>=) );
+ {
+-- import Prelude;
+ import Prelude(String,undefined,Maybe(..), (==), (>=) );
- return :: a;
- return = undefined;
+ return :: a;
+ return = undefined;
- infixl 1 >>=;
- (>>=) :: a;
- (>>=) = undefined;
+ infixl 1 >>=;
+ (>>=) :: a;
+ (>>=) = undefined;
- infixl 1 >>;
- (>>) :: a;
- (>>) = undefined;
+ infixl 1 >>;
+ (>>) :: a;
+ (>>) = undefined;
- fail :: a;
- fail = undefined;
+ fail :: a;
+ fail = undefined;
- fromInteger :: a;
- fromInteger = undefined;
+ fromInteger :: a;
+ fromInteger = undefined;
- fromRational :: a;
- fromRational = undefined;
+ fromRational :: a;
+ fromRational = undefined;
- negate :: a;
- negate = undefined;
+ negate :: a;
+ negate = undefined;
- (-) :: a;
- (-) = undefined;
+ (-) :: a;
+ (-) = undefined;
- test_do f g = do
- {
- f;
- Just a <- g;
- return a;
- };
+ test_do f g = do
+ {
+ f;
+ Just a <- g;
+ return a;
+ };
- test_fromInteger = 1;
+ test_fromInteger = 1;
- test_fromRational = 0.5;
+ test_fromRational = 0.5;
- test_negate a = - a;
+ test_negate a = - a;
- test_fromInteger_pattern 1 = undefined;
- test_fromInteger_pattern (-1) = undefined;
- test_fromInteger_pattern (a + 7) = a;
+ test_fromInteger_pattern 1 = undefined;
+ test_fromInteger_pattern (-1) = undefined;
+ test_fromInteger_pattern (a + 7) = a;
- test_fromRational_pattern 0.5 = undefined;
- test_fromRational_pattern (-0.5) = undefined;
- test_fromRational_pattern _ = undefined;
- }
+ test_fromRational_pattern 0.5 = undefined;
+ test_fromRational_pattern (-0.5) = undefined;
+ test_fromRational_pattern _ = undefined;
+ }
{-# LANGUAGE RebindableSyntax, NPlusKPatterns #-}
module Main where
- {
--- import Prelude;
- import qualified Prelude;
- import Prelude(String,undefined,Maybe(..),IO,putStrLn,
- Integer,(++),Rational, (==), (>=) );
-
- import Prelude(Monad(..),Applicative(..),Functor(..));
+ {
+-- import Prelude;
+ import qualified Prelude;
+ import Prelude(String,undefined,Maybe(..),IO,putStrLn,
+ Integer,(++),Rational, (==), (>=) );
+
+ import Prelude(Monad(..),Applicative(..),Functor(..));
import Control.Monad(ap, liftM);
- debugFunc :: String -> IO a -> IO a;
- debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
- (ioa Prelude.>>= (\a ->
- (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
- ));
+ debugFunc :: String -> IO a -> IO a;
+ debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
+ (ioa Prelude.>>= (\a ->
+ (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
+ ));
- newtype TM a = MkTM {unTM :: IO a};
+ newtype TM a = MkTM {unTM :: IO a};
instance (Functor TM) where
{
pure = return;
(<*>) = ap;
};
- instance (Monad TM) where
- {
- return a = MkTM (debugFunc "return" (Prelude.return a));
-
- (>>=) ma amb = MkTM (debugFunc ">>=" ((Prelude.>>=) (unTM ma) (\a -> unTM (amb a))));
-
- (>>) ma mb = MkTM (debugFunc ">>" ((Prelude.>>) (unTM ma) (unTM mb)));
-
- fail s = MkTM (debugFunc "fail" (Prelude.return undefined));
- };
-
- preturn a = MkTM (Prelude.return a);
-
- fromInteger :: Integer -> Integer;
- fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
-
- fromRational :: Rational -> Rational;
- fromRational a = a Prelude.+ a Prelude.+ a; -- three times
-
- negate :: a -> a;
- negate a = a; -- don't actually negate
-
- (-) :: a -> a -> a;
- (-) x y = y; -- changed function
-
-
- test_do f g = do
- {
- f; -- >>
- Just a <- g; -- >>= (and fail if g returns Nothing)
- return a; -- return
- };
-
- test_fromInteger = 27;
-
- test_fromRational = 31.5;
-
- test_negate a = - a;
-
- test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
- test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
- test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
-
- test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
- test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
- test_fromRational_pattern a = "_=" ++ (Prelude.show a);
-
- tmPutStrLn s = MkTM (putStrLn s);
-
- doTest :: String -> TM a -> IO ();
- doTest s ioa =
- (putStrLn ("start test " ++ s))
- Prelude.>>
- (unTM ioa)
- Prelude.>>
- (putStrLn ("end test " ++ s));
-
- main :: IO ();
- main =
- (doTest "test_do failure"
- (test_do (preturn ()) (preturn Nothing))
- )
- Prelude.>>
- (doTest "test_do success"
- (test_do (preturn ()) (preturn (Just ())))
- )
- Prelude.>>
- (doTest "test_fromInteger"
- (tmPutStrLn (Prelude.show test_fromInteger)) -- 27 * 5 = 135
- )
- Prelude.>>
- (doTest "test_fromRational"
- (tmPutStrLn (Prelude.show test_fromRational)) -- 31.5 * 3 = 189%2
- )
- Prelude.>>
- (doTest "test_negate"
- (tmPutStrLn (Prelude.show (test_negate 3))) -- 3 * 5 = 15, non-negate
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 1"
- (tmPutStrLn (test_fromInteger_pattern 1)) -- 1 * 5 = 5, matches "1"
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern (-2)"
- (tmPutStrLn (test_fromInteger_pattern (-2))) -- "-2" = 2 * 5 = 10
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 9"
- (tmPutStrLn (test_fromInteger_pattern 9)) -- "9" = 45, 45 "-" "7" = "7" = 35
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 0.5"
- (tmPutStrLn (test_fromRational_pattern 0.5)) -- "0.5" = 3%2
- )
- Prelude.>>
- (doTest "test_fromRational_pattern (-0.7)"
- (tmPutStrLn (test_fromRational_pattern (-0.7))) -- "-0.7" = "0.7" = 21%10
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 1.7"
- (tmPutStrLn (test_fromRational_pattern 1.7)) -- "1.7" = 51%10
- );
- }
+ instance (Monad TM) where
+ {
+ return a = MkTM (debugFunc "return" (Prelude.return a));
+
+ (>>=) ma amb = MkTM (debugFunc ">>=" ((Prelude.>>=) (unTM ma) (\a -> unTM (amb a))));
+
+ (>>) ma mb = MkTM (debugFunc ">>" ((Prelude.>>) (unTM ma) (unTM mb)));
+
+ fail s = MkTM (debugFunc "fail" (Prelude.return undefined));
+ };
+
+ preturn a = MkTM (Prelude.return a);
+
+ fromInteger :: Integer -> Integer;
+ fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
+
+ fromRational :: Rational -> Rational;
+ fromRational a = a Prelude.+ a Prelude.+ a; -- three times
+
+ negate :: a -> a;
+ negate a = a; -- don't actually negate
+
+ (-) :: a -> a -> a;
+ (-) x y = y; -- changed function
+
+
+ test_do f g = do
+ {
+ f; -- >>
+ Just a <- g; -- >>= (and fail if g returns Nothing)
+ return a; -- return
+ };
+
+ test_fromInteger = 27;
+
+ test_fromRational = 31.5;
+
+ test_negate a = - a;
+
+ test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
+ test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
+ test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
+
+ test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
+ test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
+ test_fromRational_pattern a = "_=" ++ (Prelude.show a);
+
+ tmPutStrLn s = MkTM (putStrLn s);
+
+ doTest :: String -> TM a -> IO ();
+ doTest s ioa =
+ (putStrLn ("start test " ++ s))
+ Prelude.>>
+ (unTM ioa)
+ Prelude.>>
+ (putStrLn ("end test " ++ s));
+
+ main :: IO ();
+ main =
+ (doTest "test_do failure"
+ (test_do (preturn ()) (preturn Nothing))
+ )
+ Prelude.>>
+ (doTest "test_do success"
+ (test_do (preturn ()) (preturn (Just ())))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger"
+ (tmPutStrLn (Prelude.show test_fromInteger)) -- 27 * 5 = 135
+ )
+ Prelude.>>
+ (doTest "test_fromRational"
+ (tmPutStrLn (Prelude.show test_fromRational)) -- 31.5 * 3 = 189%2
+ )
+ Prelude.>>
+ (doTest "test_negate"
+ (tmPutStrLn (Prelude.show (test_negate 3))) -- 3 * 5 = 15, non-negate
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 1"
+ (tmPutStrLn (test_fromInteger_pattern 1)) -- 1 * 5 = 5, matches "1"
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern (-2)"
+ (tmPutStrLn (test_fromInteger_pattern (-2))) -- "-2" = 2 * 5 = 10
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 9"
+ (tmPutStrLn (test_fromInteger_pattern 9)) -- "9" = 45, 45 "-" "7" = "7" = 35
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 0.5"
+ (tmPutStrLn (test_fromRational_pattern 0.5)) -- "0.5" = 3%2
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern (-0.7)"
+ (tmPutStrLn (test_fromRational_pattern (-0.7))) -- "-0.7" = "0.7" = 21%10
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 1.7"
+ (tmPutStrLn (test_fromRational_pattern 1.7)) -- "1.7" = 51%10
+ );
+ }
{-# LANGUAGE RebindableSyntax, NPlusKPatterns #-}
module Main where
- {
--- import Prelude;
- import qualified Prelude;
- import Prelude(String,undefined,Maybe(..),IO,putStrLn,
- Integer,(++),Rational, (==), (>=) );
-
- debugFunc :: String -> IO a -> IO a;
- debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
- (ioa Prelude.>>= (\a ->
- (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
- ));
-
- return :: a -> IO a;
- return a = debugFunc "return" (Prelude.return a);
-
- infixl 1 >>=;
- (>>=) :: IO a -> (a -> IO b) -> IO b;
- (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
-
- infixl 1 >>;
- (>>) :: IO a -> IO b -> IO b;
- (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
-
- fail :: String -> IO a;
- fail s = debugFunc "fail" (Prelude.return undefined);
--- fail s = debugFunc "fail" (Prelude.fail s);
-
- fromInteger :: Integer -> Integer;
- fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
-
- fromRational :: Rational -> Rational;
- fromRational a = a Prelude.+ a Prelude.+ a; -- three times
-
- negate :: a -> a;
- negate a = a; -- don't actually negate
-
- (-) :: a -> a -> a;
- (-) x y = y; -- changed function
-
-
- test_do f g = do
- {
- f; -- >>
- Just a <- g; -- >>= (and fail if g returns Nothing)
- return a; -- return
- };
-
- test_fromInteger = 27;
-
- test_fromRational = 31.5;
-
- test_negate a = - a;
-
- test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
- test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
- test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
-
- test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
- test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
- test_fromRational_pattern a = "_=" ++ (Prelude.show a);
-
-
- doTest :: String -> IO a -> IO ();
- doTest s ioa =
- (putStrLn ("start test " ++ s))
- Prelude.>>
- ioa
- Prelude.>>
- (putStrLn ("end test " ++ s));
-
- main :: IO ();
- main =
- (doTest "test_do failure"
- (test_do (Prelude.return ()) (Prelude.return Nothing))
- )
- Prelude.>>
- (doTest "test_do success"
- (test_do (Prelude.return ()) (Prelude.return (Just ())))
- )
- Prelude.>>
- (doTest "test_fromInteger"
- (putStrLn (Prelude.show test_fromInteger))
- )
- Prelude.>>
- (doTest "test_fromRational"
- (putStrLn (Prelude.show test_fromRational))
- )
- Prelude.>>
- (doTest "test_negate"
- (putStrLn (Prelude.show (test_negate 3)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 1"
- (putStrLn (test_fromInteger_pattern 1))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern (-2)"
- (putStrLn (test_fromInteger_pattern (-2)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 9"
- (putStrLn (test_fromInteger_pattern 9))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 0.5"
- (putStrLn (test_fromRational_pattern 0.5))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern (-0.7)"
- (putStrLn (test_fromRational_pattern (-0.7)))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 1.7"
- (putStrLn (test_fromRational_pattern 1.7))
- );
- }
+ {
+-- import Prelude;
+ import qualified Prelude;
+ import Prelude(String,undefined,Maybe(..),IO,putStrLn,
+ Integer,(++),Rational, (==), (>=) );
+
+ debugFunc :: String -> IO a -> IO a;
+ debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
+ (ioa Prelude.>>= (\a ->
+ (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
+ ));
+
+ return :: a -> IO a;
+ return a = debugFunc "return" (Prelude.return a);
+
+ infixl 1 >>=;
+ (>>=) :: IO a -> (a -> IO b) -> IO b;
+ (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
+
+ infixl 1 >>;
+ (>>) :: IO a -> IO b -> IO b;
+ (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
+
+ fail :: String -> IO a;
+ fail s = debugFunc "fail" (Prelude.return undefined);
+-- fail s = debugFunc "fail" (Prelude.fail s);
+
+ fromInteger :: Integer -> Integer;
+ fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
+
+ fromRational :: Rational -> Rational;
+ fromRational a = a Prelude.+ a Prelude.+ a; -- three times
+
+ negate :: a -> a;
+ negate a = a; -- don't actually negate
+
+ (-) :: a -> a -> a;
+ (-) x y = y; -- changed function
+
+
+ test_do f g = do
+ {
+ f; -- >>
+ Just a <- g; -- >>= (and fail if g returns Nothing)
+ return a; -- return
+ };
+
+ test_fromInteger = 27;
+
+ test_fromRational = 31.5;
+
+ test_negate a = - a;
+
+ test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
+ test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
+ test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
+
+ test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
+ test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
+ test_fromRational_pattern a = "_=" ++ (Prelude.show a);
+
+
+ doTest :: String -> IO a -> IO ();
+ doTest s ioa =
+ (putStrLn ("start test " ++ s))
+ Prelude.>>
+ ioa
+ Prelude.>>
+ (putStrLn ("end test " ++ s));
+
+ main :: IO ();
+ main =
+ (doTest "test_do failure"
+ (test_do (Prelude.return ()) (Prelude.return Nothing))
+ )
+ Prelude.>>
+ (doTest "test_do success"
+ (test_do (Prelude.return ()) (Prelude.return (Just ())))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger"
+ (putStrLn (Prelude.show test_fromInteger))
+ )
+ Prelude.>>
+ (doTest "test_fromRational"
+ (putStrLn (Prelude.show test_fromRational))
+ )
+ Prelude.>>
+ (doTest "test_negate"
+ (putStrLn (Prelude.show (test_negate 3)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 1"
+ (putStrLn (test_fromInteger_pattern 1))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern (-2)"
+ (putStrLn (test_fromInteger_pattern (-2)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 9"
+ (putStrLn (test_fromInteger_pattern 9))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 0.5"
+ (putStrLn (test_fromRational_pattern 0.5))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern (-0.7)"
+ (putStrLn (test_fromRational_pattern (-0.7)))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 1.7"
+ (putStrLn (test_fromRational_pattern 1.7))
+ );
+ }
{-# LANGUAGE RebindableSyntax, NPlusKPatterns #-}
module Main where
- {
--- import Prelude;
- import qualified Prelude;
- import Prelude(String,undefined,Maybe(..),IO,putStrLn,
- Integer,(++),Rational, (==), (>=) );
-
- debugFunc :: String -> IO a -> IO a;
- debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
- (ioa Prelude.>>= (\a ->
- (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
- ));
-
- infixl 1 >>=;
- infixl 1 >>;
-
- class MyMonad m where
- {
- return :: a -> m a;
- (>>=) :: m a -> (a -> m b) -> m b;
- (>>) :: m a -> m b -> m b;
- fail :: String -> m a;
- };
-
- instance MyMonad IO where
- {
- return a = debugFunc "return" (Prelude.return a);
-
- (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
-
- (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
-
- fail s = debugFunc "fail" (Prelude.return undefined);
- -- fail s = debugFunc "fail" (Prelude.fail s);
- };
-
- fromInteger :: Integer -> Integer;
- fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
-
- fromRational :: Rational -> Rational;
- fromRational a = a Prelude.+ a Prelude.+ a; -- three times
-
- negate :: a -> a;
- negate a = a; -- don't actually negate
-
- (-) :: a -> a -> a;
- (-) x y = y; -- changed function
-
-
- test_do f g = do
- {
- f; -- >>
- Just a <- g; -- >>= (and fail if g returns Nothing)
- return a; -- return
- };
-
- test_fromInteger = 27;
-
- test_fromRational = 31.5;
-
- test_negate a = - a;
-
- test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
- test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
- test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
-
- test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
- test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
- test_fromRational_pattern a = "_=" ++ (Prelude.show a);
-
-
- doTest :: String -> IO a -> IO ();
- doTest s ioa =
- (putStrLn ("start test " ++ s))
- Prelude.>>
- ioa
- Prelude.>>
- (putStrLn ("end test " ++ s));
-
- main :: IO ();
- main =
- (doTest "test_do failure"
- (test_do (Prelude.return ()) (Prelude.return Nothing))
- )
- Prelude.>>
- (doTest "test_do success"
- (test_do (Prelude.return ()) (Prelude.return (Just ())))
- )
- Prelude.>>
- (doTest "test_fromInteger"
- (putStrLn (Prelude.show test_fromInteger))
- )
- Prelude.>>
- (doTest "test_fromRational"
- (putStrLn (Prelude.show test_fromRational))
- )
- Prelude.>>
- (doTest "test_negate"
- (putStrLn (Prelude.show (test_negate 3)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 1"
- (putStrLn (test_fromInteger_pattern 1))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern (-2)"
- (putStrLn (test_fromInteger_pattern (-2)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 9"
- (putStrLn (test_fromInteger_pattern 9))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 0.5"
- (putStrLn (test_fromRational_pattern 0.5))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern (-0.7)"
- (putStrLn (test_fromRational_pattern (-0.7)))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 1.7"
- (putStrLn (test_fromRational_pattern 1.7))
- );
- }
+ {
+-- import Prelude;
+ import qualified Prelude;
+ import Prelude(String,undefined,Maybe(..),IO,putStrLn,
+ Integer,(++),Rational, (==), (>=) );
+
+ debugFunc :: String -> IO a -> IO a;
+ debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
+ (ioa Prelude.>>= (\a ->
+ (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
+ ));
+
+ infixl 1 >>=;
+ infixl 1 >>;
+
+ class MyMonad m where
+ {
+ return :: a -> m a;
+ (>>=) :: m a -> (a -> m b) -> m b;
+ (>>) :: m a -> m b -> m b;
+ fail :: String -> m a;
+ };
+
+ instance MyMonad IO where
+ {
+ return a = debugFunc "return" (Prelude.return a);
+
+ (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
+
+ (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
+
+ fail s = debugFunc "fail" (Prelude.return undefined);
+ -- fail s = debugFunc "fail" (Prelude.fail s);
+ };
+
+ fromInteger :: Integer -> Integer;
+ fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
+
+ fromRational :: Rational -> Rational;
+ fromRational a = a Prelude.+ a Prelude.+ a; -- three times
+
+ negate :: a -> a;
+ negate a = a; -- don't actually negate
+
+ (-) :: a -> a -> a;
+ (-) x y = y; -- changed function
+
+
+ test_do f g = do
+ {
+ f; -- >>
+ Just a <- g; -- >>= (and fail if g returns Nothing)
+ return a; -- return
+ };
+
+ test_fromInteger = 27;
+
+ test_fromRational = 31.5;
+
+ test_negate a = - a;
+
+ test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
+ test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
+ test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
+
+ test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
+ test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
+ test_fromRational_pattern a = "_=" ++ (Prelude.show a);
+
+
+ doTest :: String -> IO a -> IO ();
+ doTest s ioa =
+ (putStrLn ("start test " ++ s))
+ Prelude.>>
+ ioa
+ Prelude.>>
+ (putStrLn ("end test " ++ s));
+
+ main :: IO ();
+ main =
+ (doTest "test_do failure"
+ (test_do (Prelude.return ()) (Prelude.return Nothing))
+ )
+ Prelude.>>
+ (doTest "test_do success"
+ (test_do (Prelude.return ()) (Prelude.return (Just ())))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger"
+ (putStrLn (Prelude.show test_fromInteger))
+ )
+ Prelude.>>
+ (doTest "test_fromRational"
+ (putStrLn (Prelude.show test_fromRational))
+ )
+ Prelude.>>
+ (doTest "test_negate"
+ (putStrLn (Prelude.show (test_negate 3)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 1"
+ (putStrLn (test_fromInteger_pattern 1))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern (-2)"
+ (putStrLn (test_fromInteger_pattern (-2)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 9"
+ (putStrLn (test_fromInteger_pattern 9))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 0.5"
+ (putStrLn (test_fromRational_pattern 0.5))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern (-0.7)"
+ (putStrLn (test_fromRational_pattern (-0.7)))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 1.7"
+ (putStrLn (test_fromRational_pattern 1.7))
+ );
+ }
MultiParamTypeClasses, FunctionalDependencies #-}
module Main where
- {
--- import Prelude;
- import qualified Prelude;
- import Prelude(String,undefined,Maybe(..),IO,putStrLn,
- Integer,(++),Rational, (==), (>=) );
-
- debugFunc :: String -> IO a -> IO a;
- debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
- (ioa Prelude.>>= (\a ->
- (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
- ));
-
- infixl 1 >>=;
- infixl 1 >>;
-
- returnIO :: a -> IO a;
+ {
+-- import Prelude;
+ import qualified Prelude;
+ import Prelude(String,undefined,Maybe(..),IO,putStrLn,
+ Integer,(++),Rational, (==), (>=) );
+
+ debugFunc :: String -> IO a -> IO a;
+ debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
+ (ioa Prelude.>>= (\a ->
+ (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
+ ));
+
+ infixl 1 >>=;
+ infixl 1 >>;
+
+ returnIO :: a -> IO a;
returnIO = Prelude.return;
-
- class HasReturn m where
- {
- return :: a -> m a;
- };
-
- class HasBind m n mn | m n -> mn, m mn -> n where
- {
- (>>=) :: m a -> (a -> n b) -> mn b;
- };
-
- class HasSeq m n mn | m n -> mn, m mn -> n where
- {
- (>>) :: m a -> n b -> mn b;
- };
-
- class HasFail m where
- {
- fail :: String -> m a;
- };
-
- instance HasReturn IO where
- {
- return a = debugFunc "return" (returnIO a);
- };
-
- instance HasBind IO IO IO where
- {
- (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
- };
-
- instance HasSeq IO IO IO where
- {
- (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
- };
-
- instance HasFail IO where
- {
- fail s = debugFunc "fail" (returnIO undefined);
- -- fail s = debugFunc "fail" (Prelude.fail s);
- };
-
- class HasFromInteger a where
- {
- fromInteger :: a -> a;
- };
-
- instance HasFromInteger Integer where
- {
- fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
- };
-
- class HasFromRational a where
- {
- fromRational :: a -> a;
- };
-
- instance HasFromRational Rational where
- {
- fromRational a = a Prelude.+ a Prelude.+ a; -- three times
- };
-
- class HasNegate a where
- {
- negate :: a -> a;
- };
-
- instance HasNegate Integer where
- {
- negate a = a; -- don't actually negate
- };
-
- instance HasNegate Rational where
- {
- negate a = a; -- don't actually negate
- };
-
- class HasMinus a where
- {
- (-) :: a -> a -> a;
- };
-
- instance HasMinus Rational where
- {
- (-) x y = y; -- changed function
- };
-
- instance HasMinus Integer where
- {
- (-) x y = y; -- changed function
- };
-
-
- test_do f g = do
- {
- f; -- >>
- Just a <- g; -- >>= (and fail if g returns Nothing)
- return a; -- return
- };
-
- test_fromInteger :: Integer;
- test_fromInteger = 27;
-
- test_fromRational :: Rational;
- test_fromRational = 31.5;
-
- test_negate :: Integer -> Integer;
- test_negate a = - a;
-
- test_fromInteger_pattern :: Integer -> String;
- test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
- test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
- test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
-
- test_fromRational_pattern :: Rational -> String;
- test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
- test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
- test_fromRational_pattern a = "_=" ++ (Prelude.show a);
-
-
- doTest :: String -> IO a -> IO ();
- doTest s ioa =
- (putStrLn ("start test " ++ s))
- Prelude.>>
- ioa
- Prelude.>>
- (putStrLn ("end test " ++ s));
-
- main :: IO ();
- main =
- (doTest "test_do failure"
- (test_do (returnIO ()) (returnIO Nothing))
- )
- Prelude.>>
- (doTest "test_do success"
- (test_do (returnIO ()) (returnIO (Just ())))
- )
- Prelude.>>
- (doTest "test_fromInteger"
- (putStrLn (Prelude.show test_fromInteger))
- )
- Prelude.>>
- (doTest "test_fromRational"
- (putStrLn (Prelude.show test_fromRational))
- )
- Prelude.>>
- (doTest "test_negate"
- (putStrLn (Prelude.show (test_negate 3)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 1"
- (putStrLn (test_fromInteger_pattern 1))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern (-2)"
- (putStrLn (test_fromInteger_pattern (-(2::Integer)::Integer)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 9"
- (putStrLn (test_fromInteger_pattern 9))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 0.5"
- (putStrLn (test_fromRational_pattern 0.5))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern (-0.7)"
- (putStrLn (test_fromRational_pattern (-(0.7::Rational)::Rational)))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 1.7"
- (putStrLn (test_fromRational_pattern 1.7))
- )
- ;
- }
+
+ class HasReturn m where
+ {
+ return :: a -> m a;
+ };
+
+ class HasBind m n mn | m n -> mn, m mn -> n where
+ {
+ (>>=) :: m a -> (a -> n b) -> mn b;
+ };
+
+ class HasSeq m n mn | m n -> mn, m mn -> n where
+ {
+ (>>) :: m a -> n b -> mn b;
+ };
+
+ class HasFail m where
+ {
+ fail :: String -> m a;
+ };
+
+ instance HasReturn IO where
+ {
+ return a = debugFunc "return" (returnIO a);
+ };
+
+ instance HasBind IO IO IO where
+ {
+ (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
+ };
+
+ instance HasSeq IO IO IO where
+ {
+ (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
+ };
+
+ instance HasFail IO where
+ {
+ fail s = debugFunc "fail" (returnIO undefined);
+ -- fail s = debugFunc "fail" (Prelude.fail s);
+ };
+
+ class HasFromInteger a where
+ {
+ fromInteger :: a -> a;
+ };
+
+ instance HasFromInteger Integer where
+ {
+ fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
+ };
+
+ class HasFromRational a where
+ {
+ fromRational :: a -> a;
+ };
+
+ instance HasFromRational Rational where
+ {
+ fromRational a = a Prelude.+ a Prelude.+ a; -- three times
+ };
+
+ class HasNegate a where
+ {
+ negate :: a -> a;
+ };
+
+ instance HasNegate Integer where
+ {
+ negate a = a; -- don't actually negate
+ };
+
+ instance HasNegate Rational where
+ {
+ negate a = a; -- don't actually negate
+ };
+
+ class HasMinus a where
+ {
+ (-) :: a -> a -> a;
+ };
+
+ instance HasMinus Rational where
+ {
+ (-) x y = y; -- changed function
+ };
+
+ instance HasMinus Integer where
+ {
+ (-) x y = y; -- changed function
+ };
+
+
+ test_do f g = do
+ {
+ f; -- >>
+ Just a <- g; -- >>= (and fail if g returns Nothing)
+ return a; -- return
+ };
+
+ test_fromInteger :: Integer;
+ test_fromInteger = 27;
+
+ test_fromRational :: Rational;
+ test_fromRational = 31.5;
+
+ test_negate :: Integer -> Integer;
+ test_negate a = - a;
+
+ test_fromInteger_pattern :: Integer -> String;
+ test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
+ test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
+ test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
+
+ test_fromRational_pattern :: Rational -> String;
+ test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
+ test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
+ test_fromRational_pattern a = "_=" ++ (Prelude.show a);
+
+
+ doTest :: String -> IO a -> IO ();
+ doTest s ioa =
+ (putStrLn ("start test " ++ s))
+ Prelude.>>
+ ioa
+ Prelude.>>
+ (putStrLn ("end test " ++ s));
+
+ main :: IO ();
+ main =
+ (doTest "test_do failure"
+ (test_do (returnIO ()) (returnIO Nothing))
+ )
+ Prelude.>>
+ (doTest "test_do success"
+ (test_do (returnIO ()) (returnIO (Just ())))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger"
+ (putStrLn (Prelude.show test_fromInteger))
+ )
+ Prelude.>>
+ (doTest "test_fromRational"
+ (putStrLn (Prelude.show test_fromRational))
+ )
+ Prelude.>>
+ (doTest "test_negate"
+ (putStrLn (Prelude.show (test_negate 3)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 1"
+ (putStrLn (test_fromInteger_pattern 1))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern (-2)"
+ (putStrLn (test_fromInteger_pattern (-(2::Integer)::Integer)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 9"
+ (putStrLn (test_fromInteger_pattern 9))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 0.5"
+ (putStrLn (test_fromRational_pattern 0.5))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern (-0.7)"
+ (putStrLn (test_fromRational_pattern (-(0.7::Rational)::Rational)))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 1.7"
+ (putStrLn (test_fromRational_pattern 1.7))
+ )
+ ;
+ }
{-# LANGUAGE TypeFamilies #-}
module Main where
- {
- import qualified Prelude;
- import Prelude(String,undefined,Maybe(..),IO,putStrLn,
- Integer,(++),Rational, (==), (>=) );
+ {
+ import qualified Prelude;
+ import Prelude(String,undefined,Maybe(..),IO,putStrLn,
+ Integer,(++),Rational, (==), (>=) );
- debugFunc :: String -> IO a -> IO a;
- debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
- (ioa Prelude.>>= (\a ->
- (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
- ));
+ debugFunc :: String -> IO a -> IO a;
+ debugFunc s ioa = (putStrLn ("++ " ++ s)) Prelude.>>
+ (ioa Prelude.>>= (\a ->
+ (putStrLn ("-- " ++ s)) Prelude.>> (Prelude.return a)
+ ));
- infixl 1 >>=;
- infixl 1 >>;
+ infixl 1 >>=;
+ infixl 1 >>;
- returnIO :: a -> IO a;
+ returnIO :: a -> IO a;
returnIO = Prelude.return;
- class HasReturn a where
- {
- return :: a;
- };
-
- class HasBind a where
- {
- (>>=) :: a;
- };
-
- class HasSeq a where
- {
- (>>) :: a;
- };
-
- class HasFail a where
- {
- fail :: a;
- };
-
- instance HasReturn (a -> IO a) where
- {
- return a = debugFunc "return" (Prelude.return a);
- };
-
- instance HasBind (IO a -> (a -> IO b) -> IO b) where
- {
- (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
- };
-
- instance HasSeq (IO a -> IO b -> IO b) where
- {
- (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
- };
-
- instance HasFail (String -> IO a) where
- {
- fail s = debugFunc "fail" (Prelude.return undefined);
- -- fail s = debugFunc "fail" (Prelude.fail s);
- };
-
- class HasFromInteger a where
- {
- fromInteger :: a;
- };
-
- instance HasFromInteger (Integer -> Integer) where
- {
- fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
- };
-
- class HasFromRational a where
- {
- fromRational :: a;
- };
-
- instance HasFromRational (Rational -> Rational) where
- {
- fromRational a = a Prelude.+ a Prelude.+ a; -- three times
- };
-
- class HasNegate a where
- {
- negate :: a;
- };
-
- instance (b ~ (a -> a)) => HasNegate b where
- {
- negate a = a; -- don't actually negate
- };
-
- class HasMinus a where
- {
- (-) :: a;
- };
-
- instance (b ~ (a -> a -> a)) => HasMinus b where
- {
- (-) x y = y; -- changed function
- };
-
- test_do :: forall a b. IO a -> IO (Maybe b) -> IO b;
- test_do f g = do
- {
- f; -- >>
- Just (b::b) <- g; -- >>= (and fail if g returns Nothing)
- return b; -- return
- };
-
- test_fromInteger :: Integer;
- test_fromInteger = 27;
-
- test_fromRational :: Rational;
- test_fromRational = 31.5;
-
- test_negate :: Integer -> Integer;
- test_negate a = - a;
-
- test_fromInteger_pattern :: Integer -> String;
- test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
- test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
- test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
-
- test_fromRational_pattern :: Rational -> String;
- test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
- test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
- test_fromRational_pattern a = "_=" ++ (Prelude.show a);
-
-
- doTest :: String -> IO a -> IO ();
- doTest s ioa =
- (putStrLn ("start test " ++ s))
- Prelude.>>
- ioa
- Prelude.>>
- (putStrLn ("end test " ++ s));
-
- main :: IO ();
- main =
- (doTest "test_do failure"
- (test_do (Prelude.return ()) (Prelude.return Nothing))
- )
- Prelude.>>
- (doTest "test_do success"
- (test_do (Prelude.return ()) (Prelude.return (Just ())))
- )
- Prelude.>>
- (doTest "test_fromInteger"
- (putStrLn (Prelude.show test_fromInteger))
- )
- Prelude.>>
- (doTest "test_fromRational"
- (putStrLn (Prelude.show test_fromRational))
- )
- Prelude.>>
- (doTest "test_negate"
- (putStrLn (Prelude.show (test_negate 3)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 1"
- (putStrLn (test_fromInteger_pattern 1))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern (-2)"
- (putStrLn (test_fromInteger_pattern (-(2::Integer)::Integer)))
- )
- Prelude.>>
- (doTest "test_fromInteger_pattern 9"
- (putStrLn (test_fromInteger_pattern 9))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 0.5"
- (putStrLn (test_fromRational_pattern 0.5))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern (-0.7)"
- (putStrLn (test_fromRational_pattern (-(0.7::Rational)::Rational)))
- )
- Prelude.>>
- (doTest "test_fromRational_pattern 1.7"
- (putStrLn (test_fromRational_pattern 1.7))
- );
- }
+ class HasReturn a where
+ {
+ return :: a;
+ };
+
+ class HasBind a where
+ {
+ (>>=) :: a;
+ };
+
+ class HasSeq a where
+ {
+ (>>) :: a;
+ };
+
+ class HasFail a where
+ {
+ fail :: a;
+ };
+
+ instance HasReturn (a -> IO a) where
+ {
+ return a = debugFunc "return" (Prelude.return a);
+ };
+
+ instance HasBind (IO a -> (a -> IO b) -> IO b) where
+ {
+ (>>=) ma amb = debugFunc ">>=" ((Prelude.>>=) ma amb);
+ };
+
+ instance HasSeq (IO a -> IO b -> IO b) where
+ {
+ (>>) ma mb = debugFunc ">>" ((Prelude.>>) ma mb);
+ };
+
+ instance HasFail (String -> IO a) where
+ {
+ fail s = debugFunc "fail" (Prelude.return undefined);
+ -- fail s = debugFunc "fail" (Prelude.fail s);
+ };
+
+ class HasFromInteger a where
+ {
+ fromInteger :: a;
+ };
+
+ instance HasFromInteger (Integer -> Integer) where
+ {
+ fromInteger a = a Prelude.+ a Prelude.+ a Prelude.+ a Prelude.+ a; -- five times
+ };
+
+ class HasFromRational a where
+ {
+ fromRational :: a;
+ };
+
+ instance HasFromRational (Rational -> Rational) where
+ {
+ fromRational a = a Prelude.+ a Prelude.+ a; -- three times
+ };
+
+ class HasNegate a where
+ {
+ negate :: a;
+ };
+
+ instance (b ~ (a -> a)) => HasNegate b where
+ {
+ negate a = a; -- don't actually negate
+ };
+
+ class HasMinus a where
+ {
+ (-) :: a;
+ };
+
+ instance (b ~ (a -> a -> a)) => HasMinus b where
+ {
+ (-) x y = y; -- changed function
+ };
+
+ test_do :: forall a b. IO a -> IO (Maybe b) -> IO b;
+ test_do f g = do
+ {
+ f; -- >>
+ Just (b::b) <- g; -- >>= (and fail if g returns Nothing)
+ return b; -- return
+ };
+
+ test_fromInteger :: Integer;
+ test_fromInteger = 27;
+
+ test_fromRational :: Rational;
+ test_fromRational = 31.5;
+
+ test_negate :: Integer -> Integer;
+ test_negate a = - a;
+
+ test_fromInteger_pattern :: Integer -> String;
+ test_fromInteger_pattern a@1 = "1=" ++ (Prelude.show a);
+ test_fromInteger_pattern a@(-2) = "(-2)=" ++ (Prelude.show a);
+ test_fromInteger_pattern (a + 7) = "(a + 7)=" ++ Prelude.show a;
+
+ test_fromRational_pattern :: Rational -> String;
+ test_fromRational_pattern a@0.5 = "0.5=" ++ (Prelude.show a);
+ test_fromRational_pattern a@(-0.7) = "(-0.7)=" ++ (Prelude.show a);
+ test_fromRational_pattern a = "_=" ++ (Prelude.show a);
+
+
+ doTest :: String -> IO a -> IO ();
+ doTest s ioa =
+ (putStrLn ("start test " ++ s))
+ Prelude.>>
+ ioa
+ Prelude.>>
+ (putStrLn ("end test " ++ s));
+
+ main :: IO ();
+ main =
+ (doTest "test_do failure"
+ (test_do (Prelude.return ()) (Prelude.return Nothing))
+ )
+ Prelude.>>
+ (doTest "test_do success"
+ (test_do (Prelude.return ()) (Prelude.return (Just ())))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger"
+ (putStrLn (Prelude.show test_fromInteger))
+ )
+ Prelude.>>
+ (doTest "test_fromRational"
+ (putStrLn (Prelude.show test_fromRational))
+ )
+ Prelude.>>
+ (doTest "test_negate"
+ (putStrLn (Prelude.show (test_negate 3)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 1"
+ (putStrLn (test_fromInteger_pattern 1))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern (-2)"
+ (putStrLn (test_fromInteger_pattern (-(2::Integer)::Integer)))
+ )
+ Prelude.>>
+ (doTest "test_fromInteger_pattern 9"
+ (putStrLn (test_fromInteger_pattern 9))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 0.5"
+ (putStrLn (test_fromRational_pattern 0.5))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern (-0.7)"
+ (putStrLn (test_fromRational_pattern (-(0.7::Rational)::Rational)))
+ )
+ Prelude.>>
+ (doTest "test_fromRational_pattern 1.7"
+ (putStrLn (test_fromRational_pattern 1.7))
+ );
+ }
module ShouldCompile where
import Rn037Help hiding( C )
- -- C is the constructor, but we should
- -- still be able to hide it
+ -- C is the constructor, but we should
+ -- still be able to hide it
-- we should still be able to refer to the type constructor, though
type Foo = T
module ShouldCompile where
import Rn037Help hiding( C )
- -- C is the constructor, but we should
- -- still be able to hide it
+ -- C is the constructor, but we should
+ -- still be able to hide it
f x = Rn037Help.C
View.hs:14:
Couldn't match `VersionGraphClient' against `VersionGraphClient'
- Expected type: VersionGraphClient
- Inferred type: VersionGraphClient
+ Expected type: VersionGraphClient
+ Inferred type: VersionGraphClient
In the `graphClient1' field of a record
In the record construction: View {graphClient1 = graphClient}
# ghc -c View.hs
-}
--- | This module defines the fundamental structure of the (untyped)
--- objects in a repository.
---
+-- | This module defines the fundamental structure of the (untyped)
+-- objects in a repository.
+--
-- We depend circularly on CodedValue.hs. This module is compiled
-- first and uses CodedValue.hi-boot.
module View(
module RnAux017 where
-import Test -- Import main module so there really is a loop
- -- (avoid warning message)
+import Test -- Import main module so there really is a loop
+ -- (avoid warning message)
data Wibble = Wibble
data Wobble = Wobble
{-# OPTIONS_GHC -Werror -fwarn-unused-binds #-}
-- Test Trac #3221: the constructors are used by the deriving
--- clause, even though they are not exported
+-- clause, even though they are not exported
module T3221( Foo ) where
import Data.List ( reverse, sort )
-sort :: Int -- Clashes with Data.List.sort,
-sort = 4 -- but never used, so OK
-
+sort :: Int -- Clashes with Data.List.sort,
+sort = 4 -- but never used, so OK
-reverse :: Int -- Clashes with Data.List.reverse,
-reverse = 3 -- but the only uses are qualified
+
+reverse :: Int -- Clashes with Data.List.reverse,
+reverse = 3 -- but the only uses are qualified
x = ShouldCompile.reverse
module ShouldCompile( t ) where
-f x = f x -- Unused
+f x = f x -- Unused
-g x = h x -- Unused
+g x = h x -- Unused
h x = g x
-t x = t x -- Used by export list
+t x = t x -- Used by export list
module ShouldCompile (module M) where
- import Rn043_A as M -- x, M.x
- import Rn043_B -- x, Rn043_A.x
+ import Rn043_A as M -- x, M.x
+ import Rn043_B -- x, Rn043_A.x
-- GHC 6.4.1 said
-- test.hs:1:5:
--- Warning: accepting non-standard pattern guards
--- (-fglasgow-exts to suppress this message)
+-- Warning: accepting non-standard pattern guards
+-- (-fglasgow-exts to suppress this message)
-- [x <- ((1 * 2) + 3) * 4, undefined]
-- Note the wrongly-parenthesised expression
module ShouldCompile where
main | x <- 1*2+3*4 = x
-
\ No newline at end of file
a496 = a497
a497 = a498
a498 = a499
-a499 = [] -- !!! ta-dah!!!
+a499 = [] -- !!! ta-dah!!!
-- !!! rn001: super-simple set of bindings,
--- !!! incl wildcard pattern-bindings and *duplicates*
+-- !!! incl wildcard pattern-bindings and *duplicates*
x = []
y = []
f x = x
where
- a = []
- (b,c,a) = ([],[],d)
- [d,b,_] = ([],a,[])
+ a = []
+ (b,c,a) = ([],[],d)
+ [d,b,_] = ([],a,[])
module Test where
class K a where
- op1 :: a -> a -> a
- op2 :: Int -> a
+ op1 :: a -> a -> a
+ op2 :: Int -> a
instance K Int where
- op1 a b = a+b
- op2 x = x
+ op1 a b = a+b
+ op2 x = x
instance K Bool where
- op1 a b = a
- -- Pick up the default decl for op2
-
+ op1 a b = a
+ -- Pick up the default decl for op2
+
instance K [a] where
- op3 a = a -- Oops! Isn't a class op of K
-
+ op3 a = a -- Oops! Isn't a class op of K
+
| TokIs
| TokDeref
| TokFind
- | TokLiteral -- Duplicated!
+ | TokLiteral -- Duplicated!
| TokThe
deriving Show
-- !!! Precedence of unary negation
-f1 x y = x + -y -- Fails
-f2 x y = x * -y -- Fails
+f1 x y = x + -y -- Fails
+f2 x y = x * -y -- Fails
-f3 x y = -x + y -- OK: means (-x) + y
- -- since - is left associative
+f3 x y = -x + y -- OK: means (-x) + y
+ -- since - is left associative
-f4 x y = - x*y -- OK: means -(x*y)
- -- since - binds less tightly than *
+f4 x y = - x*y -- OK: means -(x*y)
+ -- since - binds less tightly than *
-f5 x y = x >= -y -- OK means x >= (-y)
+f5 x y = x >= -y -- OK means x >= (-y)
{- In GHC 4.04 this gave the terrible message:
None of the type variable(s) in the constraint `Eq a'
- appears in the type `Set a -> Set a -> Set a'
+ appears in the type `Set a -> Set a -> Set a'
In the type signature for `unionSets'
-}
--- !!! Check that type signatures and pragmas that
+-- !!! Check that type signatures and pragmas that
-- !!! don't have a "parent" are correctly reported
module ShouldFail where
{-# INLINE f #-}
-- Nested test
-h :: Int -> Int -- This one is ok
+h :: Int -> Int -- This one is ok
h x = x
where
- g :: Int -> Int -- Bogus
+ g :: Int -> Int -- Bogus
import Language.Haskell.TH
class Class a where
- c :: a
+ c :: a
mkSimpleClass :: Name -> Q [Dec]
mkSimpleClass name = do
- TyConI (DataD [] dname [] Nothing cs _) <- reify name
- ((NormalC conname []):_) <- return cs
- ClassI (ClassD [] cname [_] [] [SigD mname _]) _ <- reify ''Class
- return [InstanceD Nothing [] (AppT (ConT cname) (ConT dname)) [FunD mname
+ TyConI (DataD [] dname [] Nothing cs _) <- reify name
+ ((NormalC conname []):_) <- return cs
+ ClassI (ClassD [] cname [_] [] [SigD mname _]) _ <- reify ''Class
+ return [InstanceD Nothing [] (AppT (ConT cname) (ConT dname)) [FunD mname
[Clause [] (NormalB (ConE conname)) []]]]
import Language.Haskell.TH
class Class a where
- c :: a
+ c :: a
mkSimpleClass :: Name -> Q [Dec]
mkSimpleClass name = do
- TyConI (DataD [] dname [] Nothing cs _) <- reify name
- ((NormalC conname []):_) <- return cs
- ClassI (ClassD [] cname [_] [] [SigD mname _]) _ <- reify ''Class
- return [InstanceD Nothing [] (AppT (ConT cname) (ConT dname)) [FunD mname
+ TyConI (DataD [] dname [] Nothing cs _) <- reify name
+ ((NormalC conname []):_) <- return cs
+ ClassI (ClassD [] cname [_] [] [SigD mname _]) _ <- reify ''Class
+ return [InstanceD Nothing [] (AppT (ConT cname) (ConT dname)) [FunD mname
[Clause [] (NormalB (ConE conname)) []]]]