rc #13

Merged
crumbtoo merged 196 commits from dev into main 2024-02-13 13:22:23 -07:00
Showing only changes of commit 1164b13a1e - Show all commits

View File

@@ -17,6 +17,7 @@ import Lens.Micro.Mtl
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Text qualified as T import Data.Text qualified as T
import Data.HashMap.Strict qualified as H import Data.HashMap.Strict qualified as H
import Data.Foldable (traverse_)
import Control.Monad (foldM, void) import Control.Monad (foldM, void)
import Control.Monad.State import Control.Monad.State
import Control.Monad.Utils (mapAccumLM) import Control.Monad.Utils (mapAccumLM)
@@ -56,14 +57,20 @@ type HMError = Either TypeError
check :: Context' -> Type -> Expr' -> HMError () check :: Context' -> Type -> Expr' -> HMError ()
check g t1 e = do check g t1 e = do
t2 <- infer g e t2 <- infer g e
unify [(t1,t2)] void $ unify [(t1,t2)]
pure ()
-- | Typecheck program. I plan to allow for *some* inference in the future, but
-- in the mean time all top-level binders must have a type annotation.
checkProg :: Program' -> HMError () checkProg :: Program' -> HMError ()
checkProg p = p ^. programScDefs checkProg p = scDefs
& traversalOf k & traverse_ k
where where
k sc = undefined scDefs = p ^. programScDefs
g = gatherTypeSigs p
k :: ScDef' -> HMError ()
k sc | Just t <- lookup (sc ^. _lhs._1) g
= check g t (sc ^. _rhs)
-- | Infer the type of an expression under some context. -- | Infer the type of an expression under some context.
-- --
@@ -173,9 +180,9 @@ unify = go mempty where
| x == y = True | x == y = True
occurs _ = False occurs _ = False
buildInitialContext :: Program b -> Context b gatherTypeSigs :: Program b -> Context b
buildInitialContext p = p ^. programTypeSigs gatherTypeSigs p = p ^. programTypeSigs
& H.toList & H.toList
-- | The expression @subst x t e@ substitutes all occurences of @x@ in @e@ with -- | The expression @subst x t e@ substitutes all occurences of @x@ in @e@ with
-- @t@ -- @t@