on master help sign in
Added "if_valid" syntax rule for possibly failing Effects

Allows branching based on whether an effectful operation returning Either l r succeeds (l failure, r success) and updating the resource accordingly.

commit50c66f91e907d511021b4d6bcdf90bd9f3af574f authorEdwin Brady <ecb10@st-andrews.ac.uk> dateWed 16 Oct 2013, 17:56 (13 years ago) parent55af041
4 files changed+12−23
effects/Effects.idr+8−21 src/Idris/AbsSyntaxTree.hs−1 src/Idris/ElabTerm.hs+3 src/Idris/Parser.hs+1−1
effects/Effects.idr+8−21
@@ -146,27 +146,14 @@ effect' : {a, b: _} -> {e : Effect} ->
146146 EffM m xs (updateResTy xs prf eff) t
147147effect' {prf} e = effect prf e
148148
149−data WrapEffM : (m : Type -> Type) ->
150− List EFFECT -> List EFFECT -> Type -> Type where
151− WEffM : EffM m xs xs' t -> WrapEffM m xs xs' t
152−
153−-- wrap subprograms to prevent lifting (need to guarantee same effects as
154−-- parent!)
155−
156−test_lbl' : {x : lbl} ->
157− {default tactics { applyTactic findEffElem 20; solve; }
158− prf : EffElem e (LRes x (Either l r)) xs} ->
159− WrapEffM m (updateResTyImm xs prf (LRes x l)) xs' t ->
160− WrapEffM m (updateResTyImm xs prf (LRes x r)) xs' t ->
161− EffM m xs xs' t
162−test_lbl' {prf} (WEffM l) (WEffM r) = test_lbl prf l r
163−
164−test' : {default tactics { applyTactic findEffElem 20; solve; }
165− prf : EffElem e (Either l r) xs} ->
166− EffM m (updateResTyImm xs prf l) xs' t ->
167− EffM m (updateResTyImm xs prf r) xs' t ->
168− EffM m xs xs' t
169−test' {prf} l r = test prf l r
149+-- For making proofs implicitly for 'test' and 'test_lbl'
150+
151+syntax if_valid then [e] else [t] =
152+ test (tactics { applyTactic findEffElem 20; solve; }) t e
153+
154+syntax if_valid [lbl] then [e] else [t] =
155+ test_lbl {x=lbl} (tactics { applyTactic findEffElem 20; solve; }) t e
156+
170157
171158-- for 'do' notation
172159
src/Idris/AbsSyntaxTree.hs−1
@@ -657,7 +657,6 @@ type PDo = PDo' PTerm
657657-- The priority gives a hint as to elaboration order. Best to elaborate
658658-- things early which will help give a more concrete type to other
659659-- variables, e.g. a before (interpTy a).
660−-- TODO: priority no longer serves any purpose, drop it!
661660
662661data PArg' t = PImp { priority :: Int,
663662 machine_inf :: Bool, -- true if the machine inferred it
src/Idris/ElabTerm.hs+3
@@ -393,6 +393,7 @@ elab ist info pattern tcgen fn tm
393393 ns <- apply (Var f) (map isph args)
394394 ptm <- get_term
395395 g <- goal
396+ -- Sort so that the implicit tactics go last
396397 let (ns', eargs) = unzip $
397398 sortBy (\(_,x) (_,y) ->
398399 compare (priority x) (priority y))
@@ -942,6 +943,8 @@ runTac autoSolve ist tac
942943 then runT tac
943944 else fail "Wrong goal type"
944945 _ -> fail "Wrong goal type"
946+ runT ProofState = do g <- goal
947+ trace (show g) $ return ()
945948 runT x = fail $ "Not implemented " ++ show x
946949
947950 runReflected t = do t' <- reify ist t
src/Idris/Parser.hs+1−1
@@ -797,7 +797,7 @@ directive syn = do try (lchar '%' *> reserved "lib"); cgn <- codegen_; lib <- st
797797 <|> do try (lchar '%' *> reserved "include"); cgn <- codegen_; hdr <- stringLiteral;
798798 return [PDirective (do addHdr cgn hdr
799799 addIBC (IBCHeader cgn hdr))]
800− <|> do try (lchar '%' *> reserved "hide"); n <- iName []
800+ <|> do try (lchar '%' *> reserved "hide"); n <- fnName
801801 return [PDirective (do setAccessibility n Hidden
802802 addIBC (IBCAccess n Hidden))]
803803 <|> do try (lchar '%' *> reserved "freeze"); n <- iName []