git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Comments never hurt
e90e724Phil Freeman
src/Language/PureScript/Sugar/CaseDeclarations.hs+12
@@ -130,12 +130,20 @@ makeCaseDeclaration ident alternatives = do
130 value = foldr (Abs . Left) (Case vars binders) args
130 value = foldr (Abs . Left) (Case vars binders) args
131 return $ ValueDeclaration ident Value [] (Right value)
131 return $ ValueDeclaration ident Value [] (Right value)
132 where
132 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.
133 findName :: Binder -> Maybe (Maybe Ident)
139 findName :: Binder -> Maybe (Maybe Ident)
134 findName NullBinder = Just Nothing
140 findName NullBinder = Just Nothing
135 findName (VarBinder name) = Just (Just name)
141 findName (VarBinder name) = Just (Just name)
136 findName (PositionedBinder _ _ binder) = findName binder
142 findName (PositionedBinder _ _ binder) = findName binder
137 findName _ = Nothing
143 findName _ = Nothing
138
144
145+ -- We still have to make sure the generated names are unique, or else
146+ -- we will end up constructing an invalid function.
139 allUnique :: (Eq a) => [a] -> Bool
147 allUnique :: (Eq a) => [a] -> Bool
140 allUnique xs = length xs == length (nub xs)
148 allUnique xs = length xs == length (nub xs)
141
149
@@ -145,11 +153,15 @@ makeCaseDeclaration ident alternatives = do
145 name <- freshName
153 name <- freshName
146 return (Ident name)
154 return (Ident name)
147
155
156+ -- Combine two lists of potential names from two case alternatives
157+ -- by zipping correspoding columns.
148 resolveNames :: [Maybe (Maybe Ident)] ->
158 resolveNames :: [Maybe (Maybe Ident)] ->
149 [Maybe (Maybe Ident)] ->
159 [Maybe (Maybe Ident)] ->
150 [Maybe (Maybe Ident)]
160 [Maybe (Maybe Ident)]
151 resolveNames = zipWith resolveName
161 resolveNames = zipWith resolveName
152
162
163+ -- Resolve a pair of names. VarBinder beats NullBinder, and everything
164+ -- else results in Nothing.
153 resolveName :: Maybe (Maybe Ident) ->
165 resolveName :: Maybe (Maybe Ident) ->
154 Maybe (Maybe Ident) ->
166 Maybe (Maybe Ident) ->
155 Maybe (Maybe Ident)
167 Maybe (Maybe Ident)