rc #13

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

View File

@@ -1,6 +1,6 @@
{-| {-|
Module : Core.HindleyMilner Module : Core.HindleyMilner
Description : Hindley-Milner inference Description : Hindley-Milner type system
-} -}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
module Core.HindleyMilner module Core.HindleyMilner
@@ -18,6 +18,7 @@ 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 Data.Foldable (traverse_)
import Compiler.RLPC
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)
@@ -41,11 +42,15 @@ data TypeError
| TyErrRecursiveType Name Type | TyErrRecursiveType Name Type
-- | Untyped, potentially undefined variable -- | Untyped, potentially undefined variable
| TyErrUntypedVariable Name | TyErrUntypedVariable Name
| TyErrMissingTypeSig Name
deriving (Show, Eq) deriving (Show, Eq)
-- | Synonym for @Either TypeError@ -- | Synonym for @Either TypeError@
type HMError = Either TypeError type HMError = Either TypeError
-- TODO: better errors. Errorful-esque, with cummulative errors instead of
-- instantly dying.
-- | Assert that an expression unifies with a given type -- | Assert that an expression unifies with a given type
-- --
-- >>> let e = [coreProg|3|] -- >>> let e = [coreProg|3|]
@@ -69,8 +74,13 @@ checkProg p = scDefs
g = gatherTypeSigs p g = gatherTypeSigs p
k :: ScDef' -> HMError () k :: ScDef' -> HMError ()
k sc | Just t <- lookup (sc ^. _lhs._1) g k sc = case lookup scname g of
= check g t (sc ^. _rhs) Just t -> check g t (sc ^. _rhs)
Nothing -> Left (TyErrMissingTypeSig $ scname)
where scname = sc ^. _lhs._1
checkRlpcProg :: Program' -> RLPC TypeError ()
checkRlpcProg = undefined
-- | Infer the type of an expression under some context. -- | Infer the type of an expression under some context.
-- --