Skip to content

Instantly share code, notes, and snippets.

@jeremy-w
Created October 9, 2015 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeremy-w/80953ebe9f68064e78eb to your computer and use it in GitHub Desktop.
Save jeremy-w/80953ebe9f68064e78eb to your computer and use it in GitHub Desktop.
Very basic example of using elaborator reflection to interactively fill in a hole in a function implementation.
-- Note that :elab does not automatically do :module Language.Reflection.Elab
-- for you. When you finish a proof, the same applies, so we have to also
-- add an import statement here, otherwise we'll get an error:
--
-- When checking right hand side of Main.shouldBeEmptyString:
-- No such variable Language.Reflection.Elab.Elab
import Language.Reflection.Elab
fillMeIn : List String -> String
fillMeIn strings =
case strings of
Nil =>
-- The ? creates a hole. This can be interactively filled using
-- :elab at the Idris REPL. On completion of the proof,
-- it writes out a definition that you can paste into the file.
?shouldBeEmptyString
string :: _ =>
string
-- This is the definition written out on :qed.
-- Try commenting this out and using :elab to fill the hole yourself.
-- Don't forget to run :module Language.Reflection.Elab first!
--
-- Once you have that working, try replacing the strings variable with an
-- unused variable (hint: look at `:doc intro`, then `:doc TTName`).
{-
Main.shouldBeEmptyString = %runElab (do intro $ UN "strings"
fill $ RConstant $ Str ""
solve)
-}
{-
*SimpleElaborationExample> :printdef fillMeIn
fillMeIn : List String -> String
fillMeIn strings = case strings of
[] => shouldBeEmptyString strings
(string :: _) => string
*SimpleElaborationExample> :printdef shouldBeEmptyString
shouldBeEmptyString : List String -> String
shouldBeEmptyString = let tacticExpr =
PE_>>=_585bb10e (intro (UN "strings"))
(\bindx =>
PE_>>=_585bb10e (fill (RConstant (Str "")))
(\bindx =>
solve))
in \strings => ""
*SimpleElaborationExample> fillMeIn []
"" : String
*SimpleElaborationExample> fillMeIn ["hi", "there"]
"hi" : String
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment