@@ -8,6 +8,10 @@ module AST.Canonical
88 , TypedArg(..)
99 -- patterns
1010 , Pattern, Pattern_(..)
11+ , CtorAlts(..)
12+ , CtorAlt(..)
13+ , toAlts
14+ , ctorsToAlts
1115 , PatternCtorArg(..)
1216 , Destructors
1317 , Destructor(..)
@@ -126,11 +130,47 @@ data Pattern_
126130 { _p_home :: ModuleName.Canonical
127131 , _p_type :: N.Name
128132 , _p_vars :: [N.Name]
133+ , _p_alts :: CtorAlts
129134 , _p_name :: N.Name
130135 , _p_args :: [PatternCtorArg]
131136 }
132137
133138
139+
140+-- PATTERN CTORS
141+
142+
143+data CtorAlts =
144+ CtorAlts
145+ { _num :: Int -- result of (length _alts) to amortize O(n) cost
146+ , _alts :: [CtorAlt]
147+ }
148+ deriving (Eq)
149+
150+
151+data CtorAlt =
152+ CtorAlt
153+ { _ctor :: N.Name
154+ , _arity :: Int
155+ }
156+ deriving (Eq)
157+
158+
159+toAlts :: [CtorAlt] -> CtorAlts
160+toAlts alts =
161+ CtorAlts (length alts) alts
162+
163+
164+ctorsToAlts :: [(N.Name, [Type])] -> CtorAlts
165+ctorsToAlts ctors =
166+ CtorAlts (length ctors) (map toAlt ctors)
167+
168+
169+toAlt :: (N.Name, [Type]) -> CtorAlt
170+toAlt (ctor, argTypes) =
171+ CtorAlt ctor (length argTypes)
172+
173+
134174data PatternCtorArg =
135175 PatternCtorArg
136176 { _index :: Index.ZeroBased
@@ -139,7 +179,13 @@ data PatternCtorArg =
139179 }
140180
141181
142−type Destructors = Map.Map N.Name (A.Located Destructor)
182+
183+-- DESTRUCTORS
184+
185+
186+type Destructors =
187+ Map.Map N.Name (A.Located Destructor)
188+
143189
144190data Destructor
145191 = DIndex Index.ZeroBased Destructor