on master help sign in
Improve inference in monadic code

This makes unification treat global metavariables the same way as local metavariables. Maybe be slightly dubious if the metavariable is not intended for type inference...

commit85e68a7b698d5abd1a0f1285cb167f59f93c15e0 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateMon 10 Feb 2014, 10:11 (13 years ago) parentad178cf
5 files changed+28−8
src/Idris/Core/Unify.hs+16−7 src/Idris/ProofSearch.hs+5−1 test/interactive002/expected+2 test/interactive002/input+2 test/interactive002/interactive002.idr+3
src/Idris/Core/Unify.hs+16−7
@@ -379,9 +379,10 @@ unify ctxt env topx topy dont holes =
379379 unArgs vs xs ys
380380
381381 metavarApp tm = let (f, args) = unApply tm in
382− metavar f &&
383− all (\x -> metavarApp x) args
384− && nub args == args
382+ (metavar f &&
383+ all (\x -> metavarApp x) args
384+ && nub args == args) ||
385+ globmetavar tm
385386 metavarArgs tm = let (f, args) = unApply tm in
386387 all (\x -> metavar x || inenv x) args
387388 && nub args == args
@@ -413,14 +414,22 @@ unify ctxt env topx topy dont holes =
413414
414415 rigid (P (DCon _ _) _ _) = True
415416 rigid (P (TCon _ _) _ _) = True
416− rigid t@(P Ref _ _) = inenv t
417+ rigid t@(P Ref _ _) = inenv t || globmetavar t
417418 rigid (Constant _) = True
418419 rigid (App f a) = rigid f && rigid a
419− rigid t = not (metavar t)
420+ rigid t = not (metavar t) || globmetavar t
421+
422+ globmetavar t = case unApply t of
423+ (P _ x _, _) ->
424+ case lookupDef x ctxt of
425+ [TyDecl _ _] -> True
426+ _ -> False
427+ _ -> False
420428
421429 metavar t = case t of
422− P _ x _ -> (x `elem` holes || holeIn env x) &&
423− not (x `elem` dont)
430+ P _ x _ -> ((x `elem` holes || holeIn env x) &&
431+ not (x `elem` dont))
432+ || globmetavar t
424433 _ -> False
425434 pat t = case t of
426435 P _ x _ -> x `elem` holes || patIn env x
src/Idris/ProofSearch.hs+5−1
@@ -1,3 +1,5 @@
1+{-# LANGUAGE PatternGuards #-}
2+
13module Idris.ProofSearch(trivial, proofSearch) where
24
35import Idris.Core.Elaborate hiding (Tactic(..))
@@ -45,7 +47,9 @@ proofSearch elab fn nroot hints ist
4547
4648 findInferredTy (t : _) = elab (delab ist (toUN t))
4749
48− toUN (P nt (MN i n) ty) = P nt (UN n) ty
50+ toUN t@(P nt (MN i n) ty)
51+ | ('_':xs) <- str n = t
52+ | otherwise = P nt (UN n) ty
4953 toUN (App f a) = App (toUN f) (toUN a)
5054 toUN t = t
5155
test/interactive002/expected+2
@@ -7,3 +7,5 @@ Vect (n + m) a
77Nat
88Nat
99S n
10+String
11+()
test/interactive002/input+2
@@ -6,4 +6,6 @@
66:ps 9 plus_in1
77:ps 9 plus_out
88:ps 13 what
9+:ps 16 ifoo_arg1
10+:ps 16 ifoo_out
911
test/interactive002/interactive002.idr+3
@@ -13,5 +13,8 @@ myplus (S k) y = S (myplus k y)
1313vfun : a -> Vect n a -> Vect n a -> Vect ?what a
1414vfun v xs ys = v :: ys
1515
16+ifoo : ?ifoo_arg1 -> IO ?ifoo_out
17+ifoo x = do putStrLn x
18+ putStrLn "World"
1619
1720