git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Comments never hurt
commite90e72444744c76b986779973620105b341dc5fb authorPhil Freeman <paf31@cantab.net> dateSat 28 Mar 2015, 16:26 (12 years ago) parentf424134
1 file changed+12
src/Language/PureScript/Sugar/CaseDeclarations.hs+12
src/Language/PureScript/Sugar/CaseDeclarations.hs+12
@@ -130,12 +130,20 @@ makeCaseDeclaration ident alternatives = do
130130 value = foldr (Abs . Left) (Case vars binders) args
131131 return $ ValueDeclaration ident Value [] (Right value)
132132 where
133+ -- We will construct a table of potential names.
134+ -- VarBinders will become Just (Just _) which is a potential name.
135+ -- NullBinder will become Just Nothing, which indicates that we may
136+ -- have to generate a name.
137+ -- Everything else becomes Nothing, which indicates that we definitely
138+ --have to generate a name.
133139 findName :: Binder -> Maybe (Maybe Ident)
134140 findName NullBinder = Just Nothing
135141 findName (VarBinder name) = Just (Just name)
136142 findName (PositionedBinder _ _ binder) = findName binder
137143 findName _ = Nothing
138144
145+ -- We still have to make sure the generated names are unique, or else
146+ -- we will end up constructing an invalid function.
139147 allUnique :: (Eq a) => [a] -> Bool
140148 allUnique xs = length xs == length (nub xs)
141149
@@ -145,11 +153,15 @@ makeCaseDeclaration ident alternatives = do
145153 name <- freshName
146154 return (Ident name)
147155
156+ -- Combine two lists of potential names from two case alternatives
157+ -- by zipping correspoding columns.
148158 resolveNames :: [Maybe (Maybe Ident)] ->
149159 [Maybe (Maybe Ident)] ->
150160 [Maybe (Maybe Ident)]
151161 resolveNames = zipWith resolveName
152162
163+ -- Resolve a pair of names. VarBinder beats NullBinder, and everything
164+ -- else results in Nothing.
153165 resolveName :: Maybe (Maybe Ident) ->
154166 Maybe (Maybe Ident) ->
155167 Maybe (Maybe Ident)