@@ -49,6 +49,7 @@ import Data.Function (fix)
4949import qualified Data.IntMap as IntMap
5050import Data.List (sortOn )
5151import Data.List.NonEmpty (NonEmpty , fromList )
52+ import Data.Maybe (listToMaybe )
5253import Data.Monoid (First (.. ))
5354import qualified Data.Set as Set
5455import Data.String (IsString (.. ))
@@ -117,8 +118,7 @@ eval eval = \case
117118 u' <- eval u
118119 t' >>> u'
119120 Import ns -> S. simport ns >> dunit
120- Function n ps b -> letrec n (dabs ps (\ as ->
121- foldr (\ (p, a) m -> let' p a m) (eval b) (zip ps as)))
121+ Function n ps b -> letrec n (dabs ps (foldr (\ (p, a) m -> let' p a m) (eval b) . zip ps))
122122 Call f as -> do
123123 f' <- eval f
124124 as' <- traverse eval as
@@ -153,7 +153,7 @@ parseFile srcPath jsonPath = do
153153 let sourcePath = replaceExtensions jsonPath " py"
154154 sourceContents <- Source. fromUTF8 . B. toStrict <$> liftIO (B. readFile srcPath)
155155 let span = decrSpan (Source. totalSpan sourceContents)
156- case ( A. eitherDecodeWith A. json' (A. iparse parseGraph) contents) of
156+ case A. eitherDecodeWith A. json' (A. iparse parseGraph) contents of
157157 Left (_, err) -> throwError err
158158 Right (_, Nothing ) -> throwError " no root node found"
159159 Right (_, Just root) -> pure (sourceContents, File (Reference sourcePath span ) root)
@@ -189,7 +189,7 @@ parseTerm attrs edges = locate attrs . \case
189189 " string" -> const . String <$> attrs A. .: fromString " text"
190190 " true" -> pure (const (Bool True ))
191191 " false" -> pure (const (Bool False ))
192- " throw" -> fmap Throw <$> resolve (head edges)
192+ " throw" -> fmap Throw <$> maybe empty resolve (listToMaybe edges)
193193 " if" -> liftA3 Iff <$> findEdgeNamed edges " condition" <*> findEdgeNamed edges " consequence" <*> findEdgeNamed edges " alternative" <|> pure (const Noop )
194194 " block" -> children edges
195195 " module" -> children edges
@@ -205,7 +205,7 @@ findEdgeNamed edges name = foldMap (resolveWith (\ rep attrs -> attrs A..: fromS
205205
206206-- | Map a list of edges to a list of child nodes.
207207children :: [A. Value ] -> A. Parser (Graph -> Term )
208- children edges = fmap chain . sequenceA . map snd . sortOn fst <$> traverse (resolveWith child) edges
208+ children edges = fmap chain . traverse snd . sortOn fst <$> traverse (resolveWith child) edges
209209 where
210210 child :: (Graph -> Term ) -> A. Object -> A. Parser (Int , Graph -> Term )
211211 child term attrs = (,) <$> attrs A. .: fromString " index" <*> pure term
0 commit comments