summaryrefslogtreecommitdiff
path: root/testsuite/tests/ghc-regress/generics
diff options
context:
space:
mode:
authorJose Pedro Magalhaes <jpm@cs.uu.nl>2011-05-12 16:00:31 +0200
committerJose Pedro Magalhaes <jpm@cs.uu.nl>2011-05-12 16:00:31 +0200
commite123a07ef932b2a222ee14e40b8c5563ce9beffd (patch)
tree34a0db68d919c4eae4c99d2c0cd5207759886f2b /testsuite/tests/ghc-regress/generics
parent96780d4087a385c68c2030acdc975e1b822d548d (diff)
downloadhaskell-e123a07ef932b2a222ee14e40b8c5563ce9beffd.tar.gz
dos2unix on these two files.
Diffstat (limited to 'testsuite/tests/ghc-regress/generics')
-rw-r--r--testsuite/tests/ghc-regress/generics/GShow/GShow.hs248
-rw-r--r--testsuite/tests/ghc-regress/generics/Uniplate/GUniplate.hs106
2 files changed, 177 insertions, 177 deletions
diff --git a/testsuite/tests/ghc-regress/generics/GShow/GShow.hs b/testsuite/tests/ghc-regress/generics/GShow/GShow.hs
index d43dc59e74..3c8f2591ef 100644
--- a/testsuite/tests/ghc-regress/generics/GShow/GShow.hs
+++ b/testsuite/tests/ghc-regress/generics/GShow/GShow.hs
@@ -1,124 +1,124 @@
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE TypeSynonymInstances #-}
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE TypeOperators #-}
-{-# LANGUAGE IncoherentInstances #-} -- :-/
-{-# LANGUAGE DefaultSignatures #-}
-
-module GShow (
- -- * Generic show class
- GShow(..)
- ) where
-
-
-import GHC.Generics
-
---------------------------------------------------------------------------------
--- Generic show
---------------------------------------------------------------------------------
-
-data Type = Rec | Tup | Pref | Inf String
-
-class GShow' f where
- gshowsPrec' :: Type -> Int -> f a -> ShowS
- isNullary :: f a -> Bool
- isNullary = error "generic show (isNullary): unnecessary case"
-
-instance GShow' U1 where
- gshowsPrec' _ _ U1 = id
- isNullary _ = True
-
-instance (GShow c) => GShow' (K1 i c) where
- gshowsPrec' _ n (K1 a) = gshowsPrec n a
- isNullary _ = False
-
--- No instances for P or Rec because gshow is only applicable to types of kind *
-
-instance (GShow' a, Constructor c) => GShow' (M1 C c a) where
- gshowsPrec' _ n c@(M1 x) =
- case (fixity, conIsTuple c) of
- (Prefix,False) -> showParen (n > 10 && not (isNullary x))
- ( showString (conName c)
- . if (isNullary x) then id else showChar ' '
- . showBraces t (gshowsPrec' t 10 x))
- (Prefix,True) -> showParen (n > 10) (showBraces t (gshowsPrec' t 10 x))
- (Infix _ m,_) -> showParen (n > m) (showBraces t (gshowsPrec' t m x))
- where fixity = conFixity c
- t = if (conIsRecord c) then Rec else
- if (conIsTuple c) then Tup else
- case fixity of
- Prefix -> Pref
- Infix _ _ -> Inf (show (conName c))
- showBraces :: Type -> ShowS -> ShowS
- showBraces Rec p = showChar '{' . p . showChar '}'
- showBraces Tup p = showChar '(' . p . showChar ')'
- showBraces Pref p = p
- showBraces (Inf _) p = p
- conIsTuple c = case conName c of
- ('(':',':_) -> True
- otherwise -> False
-
- isNullary (M1 x) = isNullary x
-
-instance (Selector s, GShow' a) => GShow' (M1 S s a) where
- gshowsPrec' t n s@(M1 x) | selName s == "" = showParen (n > 10)
- (gshowsPrec' t n x)
- | otherwise = showString (selName s)
- . showString " = "
- . gshowsPrec' t 0 x
- isNullary (M1 x) = isNullary x
-
-instance (GShow' a) => GShow' (M1 D d a) where
- gshowsPrec' t n (M1 x) = gshowsPrec' t n x
-
-instance (GShow' a, GShow' b) => GShow' (a :+: b) where
- gshowsPrec' t n (L1 x) = gshowsPrec' t n x
- gshowsPrec' t n (R1 x) = gshowsPrec' t n x
-
-instance (GShow' a, GShow' b) => GShow' (a :*: b) where
- gshowsPrec' t@Rec n (a :*: b) =
- gshowsPrec' t n a . showString ", " . gshowsPrec' t n b
- gshowsPrec' t@(Inf s) n (a :*: b) =
- gshowsPrec' t n a . showString s . gshowsPrec' t n b
- gshowsPrec' t@Tup n (a :*: b) =
- gshowsPrec' t n a . showChar ',' . gshowsPrec' t n b
- gshowsPrec' t@Pref n (a :*: b) =
- gshowsPrec' t (n+1) a . showChar ' ' . gshowsPrec' t (n+1) b
-
- -- If we have a product then it is not a nullary constructor
- isNullary _ = False
-
-
-class GShow a where
- gshowsPrec :: Int -> a -> ShowS
- default gshowsPrec :: (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
- gshowsPrec n = gshowsPrec' Pref n . from
-
- gshows :: a -> ShowS
- gshows = gshowsPrec 0
-
- gshow :: a -> String
- gshow x = gshows x ""
-
-
--- Base types instances
-instance GShow Char where gshowsPrec = showsPrec
-instance GShow Int where gshowsPrec = showsPrec
-instance GShow Float where gshowsPrec = showsPrec
-instance GShow String where gshowsPrec = showsPrec
-instance GShow Bool where gshowsPrec = showsPrec
-
-intersperse :: a -> [a] -> [a]
-intersperse _ [] = []
-intersperse _ [h] = [h]
-intersperse x (h:t) = h : x : (intersperse x t)
-
-instance (GShow a) => GShow [a] where
- gshowsPrec _ l = showChar '['
- . foldr (.) id
- (intersperse (showChar ',') (map (gshowsPrec 0) l))
- . showChar ']'
-
-instance (GShow a) => GShow (Maybe a)
-instance (GShow a, GShow b) => GShow (a,b)
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE IncoherentInstances #-} -- :-/
+{-# LANGUAGE DefaultSignatures #-}
+
+module GShow (
+ -- * Generic show class
+ GShow(..)
+ ) where
+
+
+import GHC.Generics
+
+--------------------------------------------------------------------------------
+-- Generic show
+--------------------------------------------------------------------------------
+
+data Type = Rec | Tup | Pref | Inf String
+
+class GShow' f where
+ gshowsPrec' :: Type -> Int -> f a -> ShowS
+ isNullary :: f a -> Bool
+ isNullary = error "generic show (isNullary): unnecessary case"
+
+instance GShow' U1 where
+ gshowsPrec' _ _ U1 = id
+ isNullary _ = True
+
+instance (GShow c) => GShow' (K1 i c) where
+ gshowsPrec' _ n (K1 a) = gshowsPrec n a
+ isNullary _ = False
+
+-- No instances for P or Rec because gshow is only applicable to types of kind *
+
+instance (GShow' a, Constructor c) => GShow' (M1 C c a) where
+ gshowsPrec' _ n c@(M1 x) =
+ case (fixity, conIsTuple c) of
+ (Prefix,False) -> showParen (n > 10 && not (isNullary x))
+ ( showString (conName c)
+ . if (isNullary x) then id else showChar ' '
+ . showBraces t (gshowsPrec' t 10 x))
+ (Prefix,True) -> showParen (n > 10) (showBraces t (gshowsPrec' t 10 x))
+ (Infix _ m,_) -> showParen (n > m) (showBraces t (gshowsPrec' t m x))
+ where fixity = conFixity c
+ t = if (conIsRecord c) then Rec else
+ if (conIsTuple c) then Tup else
+ case fixity of
+ Prefix -> Pref
+ Infix _ _ -> Inf (show (conName c))
+ showBraces :: Type -> ShowS -> ShowS
+ showBraces Rec p = showChar '{' . p . showChar '}'
+ showBraces Tup p = showChar '(' . p . showChar ')'
+ showBraces Pref p = p
+ showBraces (Inf _) p = p
+ conIsTuple c = case conName c of
+ ('(':',':_) -> True
+ otherwise -> False
+
+ isNullary (M1 x) = isNullary x
+
+instance (Selector s, GShow' a) => GShow' (M1 S s a) where
+ gshowsPrec' t n s@(M1 x) | selName s == "" = showParen (n > 10)
+ (gshowsPrec' t n x)
+ | otherwise = showString (selName s)
+ . showString " = "
+ . gshowsPrec' t 0 x
+ isNullary (M1 x) = isNullary x
+
+instance (GShow' a) => GShow' (M1 D d a) where
+ gshowsPrec' t n (M1 x) = gshowsPrec' t n x
+
+instance (GShow' a, GShow' b) => GShow' (a :+: b) where
+ gshowsPrec' t n (L1 x) = gshowsPrec' t n x
+ gshowsPrec' t n (R1 x) = gshowsPrec' t n x
+
+instance (GShow' a, GShow' b) => GShow' (a :*: b) where
+ gshowsPrec' t@Rec n (a :*: b) =
+ gshowsPrec' t n a . showString ", " . gshowsPrec' t n b
+ gshowsPrec' t@(Inf s) n (a :*: b) =
+ gshowsPrec' t n a . showString s . gshowsPrec' t n b
+ gshowsPrec' t@Tup n (a :*: b) =
+ gshowsPrec' t n a . showChar ',' . gshowsPrec' t n b
+ gshowsPrec' t@Pref n (a :*: b) =
+ gshowsPrec' t (n+1) a . showChar ' ' . gshowsPrec' t (n+1) b
+
+ -- If we have a product then it is not a nullary constructor
+ isNullary _ = False
+
+
+class GShow a where
+ gshowsPrec :: Int -> a -> ShowS
+ default gshowsPrec :: (Generic a, GShow' (Rep a)) => Int -> a -> ShowS
+ gshowsPrec n = gshowsPrec' Pref n . from
+
+ gshows :: a -> ShowS
+ gshows = gshowsPrec 0
+
+ gshow :: a -> String
+ gshow x = gshows x ""
+
+
+-- Base types instances
+instance GShow Char where gshowsPrec = showsPrec
+instance GShow Int where gshowsPrec = showsPrec
+instance GShow Float where gshowsPrec = showsPrec
+instance GShow String where gshowsPrec = showsPrec
+instance GShow Bool where gshowsPrec = showsPrec
+
+intersperse :: a -> [a] -> [a]
+intersperse _ [] = []
+intersperse _ [h] = [h]
+intersperse x (h:t) = h : x : (intersperse x t)
+
+instance (GShow a) => GShow [a] where
+ gshowsPrec _ l = showChar '['
+ . foldr (.) id
+ (intersperse (showChar ',') (map (gshowsPrec 0) l))
+ . showChar ']'
+
+instance (GShow a) => GShow (Maybe a)
+instance (GShow a, GShow b) => GShow (a,b)
diff --git a/testsuite/tests/ghc-regress/generics/Uniplate/GUniplate.hs b/testsuite/tests/ghc-regress/generics/Uniplate/GUniplate.hs
index 7b08c7e638..76f387d636 100644
--- a/testsuite/tests/ghc-regress/generics/Uniplate/GUniplate.hs
+++ b/testsuite/tests/ghc-regress/generics/Uniplate/GUniplate.hs
@@ -1,53 +1,53 @@
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE TypeSynonymInstances #-}
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE FlexibleContexts #-}
-{-# LANGUAGE TypeOperators #-}
-{-# LANGUAGE DefaultSignatures #-}
-{-# LANGUAGE IncoherentInstances #-} -- necessary, unfortunately
-
-module GUniplate where
-
-import GHC.Generics
-
---------------------------------------------------------------------------------
--- Generic Uniplate
---------------------------------------------------------------------------------
-
-class Uniplate' f b where
- children' :: f a -> [b]
-
-instance Uniplate' U1 a where
- children' U1 = []
-
-instance Uniplate' (K1 i a) a where
- children' (K1 a) = [a]
-
-instance Uniplate' (K1 i a) b where
- children' (K1 _) = []
-
-instance (Uniplate' f b) => Uniplate' (M1 i c f) b where
- children' (M1 a) = children' a
-
-instance (Uniplate' f b, Uniplate' g b) => Uniplate' (f :+: g) b where
- children' (L1 a) = children' a
- children' (R1 a) = children' a
-
-instance (Uniplate' f b, Uniplate' g b) => Uniplate' (f :*: g) b where
- children' (a :*: b) = children' a ++ children' b
-
-
-class Uniplate a where
- children :: a -> [a]
- default children :: (Generic a, Uniplate' (Rep a) a) => a -> [a]
- children = children' . from
-
-
--- Base types instances
-instance Uniplate Char where children _ = []
-instance Uniplate Int where children _ = []
-instance Uniplate Float where children _ = []
-
-instance Uniplate [a] where
- children [] = []
- children (_:t) = [t]
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE DefaultSignatures #-}
+{-# LANGUAGE IncoherentInstances #-} -- necessary, unfortunately
+
+module GUniplate where
+
+import GHC.Generics
+
+--------------------------------------------------------------------------------
+-- Generic Uniplate
+--------------------------------------------------------------------------------
+
+class Uniplate' f b where
+ children' :: f a -> [b]
+
+instance Uniplate' U1 a where
+ children' U1 = []
+
+instance Uniplate' (K1 i a) a where
+ children' (K1 a) = [a]
+
+instance Uniplate' (K1 i a) b where
+ children' (K1 _) = []
+
+instance (Uniplate' f b) => Uniplate' (M1 i c f) b where
+ children' (M1 a) = children' a
+
+instance (Uniplate' f b, Uniplate' g b) => Uniplate' (f :+: g) b where
+ children' (L1 a) = children' a
+ children' (R1 a) = children' a
+
+instance (Uniplate' f b, Uniplate' g b) => Uniplate' (f :*: g) b where
+ children' (a :*: b) = children' a ++ children' b
+
+
+class Uniplate a where
+ children :: a -> [a]
+ default children :: (Generic a, Uniplate' (Rep a) a) => a -> [a]
+ children = children' . from
+
+
+-- Base types instances
+instance Uniplate Char where children _ = []
+instance Uniplate Int where children _ = []
+instance Uniplate Float where children _ = []
+
+instance Uniplate [a] where
+ children [] = []
+ children (_:t) = [t]