@@ -8,6 +8,10 @@ module AST.Canonical
8 , TypedArg(..)
8 , TypedArg(..)
9 -- patterns
9 -- patterns
10 , Pattern, Pattern_(..)
10 , Pattern, Pattern_(..)
11 , PatternCtorArg(..)
15 , PatternCtorArg(..)
12 , Destructors
16 , Destructors
13 , Destructor(..)
17 , Destructor(..)
@@ -126,11 +130,47 @@ data Pattern_
126 { _p_home :: ModuleName.Canonical
130 { _p_home :: ModuleName.Canonical
127 , _p_type :: N.Name
131 , _p_type :: N.Name
128 , _p_vars :: [N.Name]
132 , _p_vars :: [N.Name]
133+ , _p_alts :: CtorAlts
129 , _p_name :: N.Name
134 , _p_name :: N.Name
130 , _p_args :: [PatternCtorArg]
135 , _p_args :: [PatternCtorArg]
145+ { _num :: Int -- result of (length _alts) to amortize O(n) cost
146+ , _alts :: [CtorAlt]
159+toAlts :: [CtorAlt] -> CtorAlts
161+ CtorAlts (length alts) alts
164+ctorsToAlts :: [(N.Name, [Type])] -> CtorAlts
166+ CtorAlts (length ctors) (map toAlt ctors)
169+toAlt :: (N.Name, [Type]) -> CtorAlt
170+toAlt (ctor, argTypes) =
171+ CtorAlt ctor (length argTypes)
134data PatternCtorArg =
174data PatternCtorArg =
135 PatternCtorArg
175 PatternCtorArg
136 { _index :: Index.ZeroBased
176 { _index :: Index.ZeroBased
@@ -139,7 +179,13 @@ data PatternCtorArg =
142−type Destructors = Map.Map N.Name (A.Located Destructor)
187+ Map.Map N.Name (A.Located Destructor)
144data Destructor
190data Destructor
145 = DIndex Index.ZeroBased Destructor
191 = DIndex Index.ZeroBased Destructor