Adjust old type checker to new syntax, and refactor lambda lifter to use typed AST

This commit is contained in:
Martin Fredin 2023-02-15 23:55:16 +01:00
parent 514c809b1e
commit 210e55bb15
18 changed files with 554 additions and 145 deletions

View file

@ -1,4 +1,4 @@
{-# LANGUAGE LambdaCase #-}
module Auxiliary (module Auxiliary) where
import Control.Monad.Error.Class (liftEither)
import Control.Monad.Except (MonadError)
@ -9,3 +9,13 @@ snoc x xs = xs ++ [x]
maybeToRightM :: MonadError l m => l -> Maybe r -> m r
maybeToRightM err = liftEither . maybeToRight err
mapAccumM :: Monad m => (s -> a -> m (s, b)) -> s -> [a] -> m (s, [b])
mapAccumM f = go
where
go acc = \case
[] -> pure (acc, [])
x:xs -> do
(acc', x') <- f acc x
(acc'', xs') <- go acc' xs
pure (acc'', x':xs')