compiler: de-lhs basicTypes/
[ghc.git] / compiler / basicTypes / ConLike.hs
1 {-
2 (c) The University of Glasgow 2006
3 (c) The GRASP/AQUA Project, Glasgow University, 1998
4
5 \section[ConLike]{@ConLike@: Constructor-like things}
6 -}
7
8 {-# LANGUAGE CPP, DeriveDataTypeable #-}
9
10 module ConLike (
11 ConLike(..)
12 ) where
13
14 #include "HsVersions.h"
15
16 import {-# SOURCE #-} DataCon (DataCon)
17 import {-# SOURCE #-} PatSyn (PatSyn)
18 import Outputable
19 import Unique
20 import Util
21 import Name
22
23 import Data.Function (on)
24 import qualified Data.Data as Data
25 import qualified Data.Typeable
26
27 {-
28 ************************************************************************
29 * *
30 \subsection{Constructor-like things}
31 * *
32 ************************************************************************
33 -}
34
35 -- | A constructor-like thing
36 data ConLike = RealDataCon DataCon
37 | PatSynCon PatSyn
38 deriving Data.Typeable.Typeable
39
40 {-
41 ************************************************************************
42 * *
43 \subsection{Instances}
44 * *
45 ************************************************************************
46 -}
47
48 instance Eq ConLike where
49 (==) = (==) `on` getUnique
50 (/=) = (/=) `on` getUnique
51
52 instance Ord ConLike where
53 (<=) = (<=) `on` getUnique
54 (<) = (<) `on` getUnique
55 (>=) = (>=) `on` getUnique
56 (>) = (>) `on` getUnique
57 compare = compare `on` getUnique
58
59 instance Uniquable ConLike where
60 getUnique (RealDataCon dc) = getUnique dc
61 getUnique (PatSynCon ps) = getUnique ps
62
63 instance NamedThing ConLike where
64 getName (RealDataCon dc) = getName dc
65 getName (PatSynCon ps) = getName ps
66
67 instance Outputable ConLike where
68 ppr (RealDataCon dc) = ppr dc
69 ppr (PatSynCon ps) = ppr ps
70
71 instance OutputableBndr ConLike where
72 pprInfixOcc (RealDataCon dc) = pprInfixOcc dc
73 pprInfixOcc (PatSynCon ps) = pprInfixOcc ps
74 pprPrefixOcc (RealDataCon dc) = pprPrefixOcc dc
75 pprPrefixOcc (PatSynCon ps) = pprPrefixOcc ps
76
77 instance Data.Data ConLike where
78 -- don't traverse?
79 toConstr _ = abstractConstr "ConLike"
80 gunfold _ _ = error "gunfold"
81 dataTypeOf _ = mkNoRepType "ConLike"