Skip to content

Commit 97d123e

Browse files
paf31garyb
authored andcommitted
First work on fixing the skolems bug purescript#147
1 parent 7873a98 commit 97d123e

File tree

9 files changed

+191
-117
lines changed

9 files changed

+191
-117
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module SkolemEscape where
2+
3+
import Prelude
4+
import Eff
5+
import ST
6+
7+
test _ = do
8+
r <- runST (newSTRef 0)
9+
ret 0

examples/passing/Eff.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ test1 = catchError (\s -> ret 0) $ do
1010
trace "Testing"
1111
throwError "Error!"
1212

13-
test2 = runPure $ runST $ do
13+
test2 = runST (do
1414
ref <- newSTRef 0
1515
modifySTRef ref $ \n -> n + 1
16-
readSTRef ref
16+
readSTRef ref)
1717

1818
module Main where
1919

@@ -24,4 +24,4 @@ import TestEff
2424
main = do
2525
n <- test1
2626
Trace.print n
27-
Trace.print test2
27+
--Trace.print test2

src/Language/PureScript/CodeGen/JS.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ runtimeTypeChecks arg ty =
128128
where
129129
getFunctionArgumentType :: Type -> Maybe Type
130130
getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
131-
getFunctionArgumentType (ForAll _ ty') = getFunctionArgumentType ty'
131+
getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
132132
getFunctionArgumentType _ = Nothing
133133
argumentCheck :: JS -> Type -> [JS]
134134
argumentCheck val t | t == tyNumber = [typeCheck val "number"]
@@ -141,7 +141,7 @@ runtimeTypeChecks arg ty =
141141
in
142142
typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
143143
argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
144-
argumentCheck val (ForAll _ ty') = argumentCheck val ty'
144+
argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
145145
argumentCheck _ _ = []
146146
typeCheck :: JS -> String -> JS
147147
typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
@@ -253,7 +253,7 @@ isOnlyConstructor m e ctor =
253253
where
254254
numConstructors ty = length $ filter (\(ty1, _) -> ((==) `on` typeConstructor) ty ty1) $ M.elems $ dataConstructors e
255255
typeConstructor (TypeConstructor qual) = qualify m qual
256-
typeConstructor (ForAll _ ty) = typeConstructor ty
256+
typeConstructor (ForAll _ ty _) = typeConstructor ty
257257
typeConstructor (TypeApp (TypeApp t _) ty) | t == tyFunction = typeConstructor ty
258258
typeConstructor (TypeApp ty _) = typeConstructor ty
259259
typeConstructor fn = error $ "Invalid arguments to typeConstructor: " ++ show fn

src/Language/PureScript/Pretty/Types.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ typeLiterals = mkPattern match
3636
match (TypeApp arr ty) | arr == tyArray = Just $ "[" ++ prettyPrintType ty ++ "]"
3737
match (TypeConstructor ctor) = Just $ show ctor
3838
match (TUnknown (Unknown u)) = Just $ 'u' : show u
39-
match (Skolem s) = Just $ 's' : show s
39+
match (Skolem s _) = Just $ 's' : show s
4040
match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ prettyPrintType ty' ++ ")") deps) ++ ") => " ++ prettyPrintType ty
4141
match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
42-
match (ForAll ident ty) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
42+
match (ForAll ident ty _) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
4343
match REmpty = Just $ prettyPrintRow REmpty
4444
match row@(RCons _ _ _) = Just $ prettyPrintRow row
4545
match _ = Nothing
@@ -56,7 +56,7 @@ prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs
5656
tailToPs REmpty = ""
5757
tailToPs (TUnknown (Unknown u)) = " | u" ++ show u
5858
tailToPs (TypeVar var) = " | " ++ var
59-
tailToPs (Skolem s) = " | s" ++ show s
59+
tailToPs (Skolem s _) = " | s" ++ show s
6060
tailToPs _ = error "Invalid row tail"
6161
toList :: [(String, Type)] -> Type -> ([(String, Type)], Type)
6262
toList tys (RCons name ty row) = toList ((name, ty):tys) row

src/Language/PureScript/Sugar/TypeClasses.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typeClassMemberToDictionaryAccessor :: ProperName -> String -> Declaration -> De
7474
typeClassMemberToDictionaryAccessor name arg (TypeDeclaration ident ty) =
7575
ExternDeclaration TypeClassAccessorImport ident
7676
(Just (JSFunction (Just $ identToJs ident) ["dict"] (JSBlock [JSReturn (JSAccessor (identToJs ident) (JSVar "dict"))])))
77-
(ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty))
77+
(ForAll arg (ConstrainedType [(Qualified Nothing name, TypeVar arg)] ty) Nothing)
7878
typeClassMemberToDictionaryAccessor _ _ _ = error "Invalid declaration in type class definition"
7979

8080
typeInstanceDictionaryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> [Declaration] -> Desugar Declaration
@@ -120,7 +120,7 @@ qualifiedToString mn (Qualified Nothing pn) = qualifiedToString mn (Qualified (J
120120
qualifiedToString _ (Qualified (Just (ModuleName mn)) pn) = runProperName mn ++ "_" ++ runProperName pn
121121

122122
quantify :: Type -> Type
123-
quantify ty' = foldr ForAll ty' tyVars
123+
quantify ty' = foldr (\arg t -> ForAll arg t Nothing) ty' tyVars
124124
where
125125
tyVars = nub $ everything (++) (mkQ [] collect) ty'
126126
collect (TypeVar v) = [v]

src/Language/PureScript/TypeChecker.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ typeCheckAll currentModule (d@(ImportDeclaration moduleName idents) : rest) = do
230230
addTypeClassDictionaries [tcd { tcdName = (Qualified (Just currentModule) ident), tcdType = TCDAlias (tcdName tcd) }]
231231
constructs (TypeConstructor (Qualified (Just mn) pn')) pn
232232
= mn == moduleName && pn' == pn
233-
constructs (ForAll _ ty) pn = ty `constructs` pn
233+
constructs (ForAll _ ty _) pn = ty `constructs` pn
234234
constructs (TypeApp (TypeApp t _) ty) pn | t == tyFunction = ty `constructs` pn
235235
constructs (TypeApp ty _) pn = ty `constructs` pn
236236
constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn

src/Language/PureScript/TypeChecker/Kinds.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ infer (TypeApp t1 t2) = do
142142
k2 <- infer t2
143143
k1 =?= FunKind k2 k0
144144
return k0
145-
infer (ForAll ident ty) = do
145+
infer (ForAll ident ty _) = do
146146
k <- fresh
147147
Just moduleName <- checkCurrentModule <$> get
148148
bindLocalTypeVariables moduleName [(ProperName ident, k)] $ infer ty

0 commit comments

Comments
 (0)