on master help sign in
New matching rule for solving simple functions

This applies only at the end of unification: if a constant function returning a constructor form would solve a metavariable, fill it in.

commit2a0056afac873ef75bf812b2e9b24bf37ee4501e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateFri 30 May 2014, 19:10 (12 years ago) parentcc99207
2 files changed+17−1
src/Idris/Core/Unify.hs+14−1 src/Idris/ElabTerm.hs+3
src/Idris/Core/Unify.hs+14−1
@@ -69,7 +69,20 @@ match_unify ctxt env topx topy inj holes from =
6969 return (map (renameBinders env) (trimSolutions v))
7070 _ -> tfail e
7171 where
72−
72+ -- This rule is highly dubious... it certainly produces a valid answer
73+ -- but it scares me. However, matching is never guaranteed to give a unique
74+ -- answer, merely a valid one, so perhaps we're okay.
75+ -- In other words: it may vanish without warning some day :)
76+ un names x tm@(App (P _ f (Bind fn (Pi t) sc)) a)
77+ | (P (DCon _ _) _ _, _) <- unApply x,
78+ holeIn env f || f `elem` holes
79+ = let n' = uniqueName (sMN 0 "mv") (map fst env) in
80+ checkCycle names (f, Bind n' (Lam t) x)
81+ un names tm@(App (P _ f (Bind fn (Pi t) sc)) a) x
82+ | (P (DCon _ _) _ _, _) <- unApply x,
83+ holeIn env f || f `elem` holes
84+ = let n' = uniqueName fn (map fst env) in
85+ checkCycle names (f, Bind n' (Lam t) x)
7386
7487 un names (P _ x _) tm
7588 | holeIn env x || x `elem` holes
src/Idris/ElabTerm.hs+3
@@ -698,6 +698,9 @@ elab ist info pattern opts fn tm
698698 addImpl ist (PApp fc (PRef fc (sUN "Delay"))
699699 [pexp t])
700700
701+ -- case is tricky enough without implicit coercions! If they are needed,
702+ -- they can go in the branches separately.
703+ insertCoerce ina t@(PCase _ _ _) = return t
701704 insertCoerce ina t =
702705 do ty <- goal
703706 -- Check for possible coercions to get to the goal