@@ -29,6 +29,7 @@ import Prelude.Compat
30import Data.List (nub, (\\))
30import Data.List (nub, (\\))
31import Data.Monoid
31import Data.Monoid
32+import Data.Functor.Identity (Identity(), runIdentity)
33import Control.Monad.Error.Class (MonadError(..))
34import Control.Monad.Error.Class (MonadError(..))
34import Control.Monad.State.Class (MonadState(..), gets, modify)
35import Control.Monad.State.Class (MonadState(..), gets, modify)
@@ -38,6 +39,7 @@ import Language.PureScript.AST
38import Language.PureScript.Errors
39import Language.PureScript.Errors
39import Language.PureScript.TypeChecker.Monad
40import Language.PureScript.TypeChecker.Monad
40import Language.PureScript.Types
41import Language.PureScript.Types
42+import Language.PureScript.Traversals (defS)
43-- Generate a new skolem constant
45-- Generate a new skolem constant
@@ -78,16 +80,26 @@ skolemize ident sko scope = replaceTypeVars ident (Skolem ident sko scope)
78-- only example of scoped type variables.
80-- only example of scoped type variables.
80skolemizeTypesInValue :: String -> Int -> SkolemScope -> Expr -> Expr
82skolemizeTypesInValue :: String -> Int -> SkolemScope -> Expr -> Expr
81−skolemizeTypesInValue ident sko scope = let (_, f, _) = everywhereOnValues id onExpr onBinder in f
83+skolemizeTypesInValue ident sko scope =
85+ (_, f, _, _, _) = everywhereWithContextOnValuesM [] defS onExpr onBinder defS defS
83− onExpr :: Expr -> Expr
88+ onExpr :: [String] -> Expr -> Identity ([String], Expr)
89+ onExpr sco (SuperClassDictionary c ts)
84− onExpr (SuperClassDictionary c ts) = SuperClassDictionary c (map (skolemize ident sko scope) ts)
90+ | ident `notElem` sco = return (sco, SuperClassDictionary c (map (skolemize ident sko scope) ts))
91+ onExpr sco (TypedValue check val ty)
85− onExpr (TypedValue check val ty) = TypedValue check val (skolemize ident sko scope ty)
92+ | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedValue check val (skolemize ident sko scope ty))
86− onExpr other = other
93+ onExpr sco other = return (sco, other)
88− onBinder :: Binder -> Binder
95+ onBinder :: [String] -> Binder -> Identity ([String], Binder)
96+ onBinder sco (TypedBinder ty b)
89− onBinder (TypedBinder ty b) = TypedBinder (skolemize ident sko scope ty) b
97+ | ident `notElem` sco = return (sco ++ peelTypeVars ty, TypedBinder (skolemize ident sko scope ty) b)
90− onBinder other = other
98+ onBinder sco other = return (sco, other)
100+ peelTypeVars :: Type -> [String]
101+ peelTypeVars (ForAll i ty _) = i : peelTypeVars ty
93-- Ensure skolem variables do not escape their scope
105-- Ensure skolem variables do not escape their scope