git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #550 from purescript/536

Add case for function application to a type class dictionary

commit524f8e483a26dce24ddf54cbb68c5a5cae1d481c authorPhil Freeman <paf31@cantab.net> dateThu 7 Aug 2014, 16:11 (12 years ago) parent94c24d1321a89e
2 files changed+22−3
examples/passing/CheckTypeClass.purs+16 src/Language/PureScript/TypeChecker/Types.hs+6−3
examples/passing/CheckTypeClass.pursnew file+16
@@ -0,0 +1,16 @@
1+module Main where
2+
3+ data Bar a = Bar
4+ data Baz
5+
6+ class Foo a where
7+ foo :: Bar a -> Baz
8+
9+ foo_ :: forall a. (Foo a) => a -> Baz
10+ foo_ x = foo ((mkBar :: forall a. (Foo a) => a -> Bar a) x)
11+
12+ mkBar :: forall a. a -> Bar a
13+ mkBar _ = Bar
14+
15+ main = Debug.Trace.trace "Done"
16+
src/Language/PureScript/TypeChecker/Types.hs+6−3
@@ -911,12 +911,13 @@ check' (TypedValue checkType val ty1) ty2 = do
911911 kind <- liftCheck $ kindOf moduleName ty1
912912 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
913913 ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
914− val' <- subsumes (Just val) ty1' ty2
914+ ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty2
915+ val' <- subsumes (Just val) ty1' ty2'
915916 case val' of
916917 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
917918 Just val'' -> do
918− val''' <- if checkType then check val'' ty1' else return val''
919− return $ TypedValue checkType (TypedValue True val''' ty1) ty2
919+ val''' <- if checkType then check val'' ty2' else return val''
920+ return $ TypedValue checkType (TypedValue True val''' ty1') ty2'
920921check' (Case vals binders) ret = do
921922 vals' <- mapM infer vals
922923 let ts = map (\(TypedValue _ _ t) -> t) vals'
@@ -1046,6 +1047,8 @@ checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
10461047checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
10471048 dicts <- getTypeClassDictionaries
10481049 checkFunctionApplication' (foldl App fn (map (flip (TypeClassDictionary True) dicts) constraints)) fnTy arg ret
1050+checkFunctionApplication' fn fnTy dict@(TypeClassDictionary _ _ _) _ =
1051+ return (fnTy, App fn dict)
10491052checkFunctionApplication' _ fnTy arg _ = throwError . strMsg $ "Cannot apply a function of type "
10501053 ++ prettyPrintType fnTy
10511054 ++ " to argument " ++ prettyPrintValue arg