Skip to content

Commit 117d5d3

Browse files
committed
New approach to unification
1 parent 80fb351 commit 117d5d3

File tree

15 files changed

+635
-633
lines changed

15 files changed

+635
-633
lines changed

psci/PSCi.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ import Control.Arrow (first)
3535
import Control.Monad
3636
import Control.Monad.Error.Class (MonadError(..))
3737
import Control.Monad.Trans.Class
38-
import Control.Monad.Trans.Except (runExceptT)
38+
import Control.Monad.Trans.Except (ExceptT(), runExceptT)
3939
import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
4040
import Control.Monad.Trans.State.Strict
4141
import Control.Monad.IO.Class (liftIO)
42-
import Control.Monad.Writer.Strict (runWriter)
43-
import qualified Control.Monad.Trans.State.Lazy as L
42+
import Control.Monad.Writer.Strict (Writer(), runWriter)
4443

4544
import Options.Applicative as Opts
4645

@@ -424,8 +423,11 @@ handleKindOf typ = do
424423
Right env' ->
425424
case M.lookup (P.Qualified (Just mName) $ P.ProperName "IT") (P.typeSynonyms env') of
426425
Just (_, typ') -> do
427-
let chk = P.CheckState env' 0 0 (Just mName)
428-
k = fst . runWriter . runExceptT $ L.runStateT (P.unCheck (P.kindOf typ')) chk
426+
let chk = (P.emptyCheckState env') { P.checkCurrentModule = Just mName }
427+
k = check (P.kindOf typ') chk
428+
429+
check :: StateT P.CheckState (ExceptT P.MultipleErrors (Writer P.MultipleErrors)) a -> P.CheckState -> Either P.MultipleErrors (a, P.CheckState)
430+
check sew cs = fst . runWriter . runExceptT . runStateT sew $ cs
429431
case k of
430432
Left errStack -> PSCI . outputStrLn . P.prettyPrintMultipleErrors False $ errStack
431433
Right (kind, _) -> PSCI . outputStrLn . P.prettyPrintKind $ kind

purescript.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ library
173173
Language.PureScript.Publish.BoxesHelpers
174174

175175
Control.Monad.Logger
176-
Control.Monad.Unify
177176
Control.Monad.Supply
178177
Control.Monad.Supply.Class
179178

src/Control/Monad/Unify.hs

Lines changed: 0 additions & 160 deletions
This file was deleted.

src/Language/PureScript/Errors.hs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import Data.Foldable (fold)
3232
import qualified Data.Map as M
3333

3434
import Control.Monad
35-
import Control.Monad.Unify
3635
import Control.Monad.Writer
3736
import Control.Monad.Error.Class (MonadError(..))
3837
#if __GLASGOW_HASKELL__ < 710
@@ -183,12 +182,6 @@ data HintCategory
183182

184183
data ErrorMessage = ErrorMessage [ErrorMessageHint] SimpleErrorMessage deriving (Show)
185184

186-
instance UnificationError Type ErrorMessage where
187-
occursCheckFailed t = ErrorMessage [] $ InfiniteType t
188-
189-
instance UnificationError Kind ErrorMessage where
190-
occursCheckFailed k = ErrorMessage [] $ InfiniteKind k
191-
192185
-- |
193186
-- Get the error code for a particular error type
194187
--
@@ -291,12 +284,6 @@ errorCode em = case unwrapErrorMessage em of
291284
newtype MultipleErrors = MultipleErrors
292285
{ runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
293286

294-
instance UnificationError Type MultipleErrors where
295-
occursCheckFailed t = MultipleErrors [occursCheckFailed t]
296-
297-
instance UnificationError Kind MultipleErrors where
298-
occursCheckFailed k = MultipleErrors [occursCheckFailed k]
299-
300287
-- | Check whether a collection of errors is empty or not.
301288
nonEmpty :: MultipleErrors -> Bool
302289
nonEmpty = not . null . runMultipleErrors
@@ -326,7 +313,7 @@ addHint hint = onErrorMessages $ \(ErrorMessage hints se) -> ErrorMessage (hint
326313
data LabelType = TypeLabel | SkolemLabel String deriving (Show, Read, Eq, Ord)
327314

328315
-- | A map from rigid type variable name/unknown variable pairs to new variables.
329-
type UnknownMap = M.Map (LabelType, Unknown) Unknown
316+
type UnknownMap = M.Map (LabelType, Int) Int
330317

331318
-- | How critical the issue is
332319
data Level = Error | Warning deriving Show
@@ -340,7 +327,7 @@ unwrapErrorMessage (ErrorMessage _ se) = se
340327
replaceUnknowns :: Type -> State UnknownMap Type
341328
replaceUnknowns = everywhereOnTypesM replaceTypes
342329
where
343-
lookupTable :: (LabelType, Unknown) -> UnknownMap -> (Unknown, UnknownMap)
330+
lookupTable :: (LabelType, Int) -> UnknownMap -> (Int, UnknownMap)
344331
lookupTable x m = case M.lookup x m of
345332
Nothing -> let i = length (filter (on (==) fst x) (M.keys m)) in (i, M.insert x i m)
346333
Just i -> (i, m)

src/Language/PureScript/Kinds.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import qualified Data.Aeson.TH as A
2424
#if __GLASGOW_HASKELL__ < 710
2525
import Control.Applicative
2626
#endif
27-
import Control.Monad.Unify (Unknown)
2827

2928
-- |
3029
-- The data type of kinds
@@ -33,7 +32,7 @@ data Kind
3332
-- |
3433
-- Unification variable of type Kind
3534
--
36-
= KUnknown Unknown
35+
= KUnknown Int
3736
-- |
3837
-- The kind of types
3938
--

0 commit comments

Comments
 (0)