I am writing a basic monadic parser in Idris, to get used to the syntax and differences from Haskell. I have the basics of that working just fine, but I am stuck on trying to create VerifiedSemigroup and VerifiedMonoid instances for the parser.
Without further ado, here's the parser type, Semigroup, and Monoid instances, and the start of a VerifiedSemigroup instance.
data ParserM a = Parser (String -> List (a, String))
parse : ParserM a -> String -> List (a, String)
parse (Parser p) = p
instance Semigroup (ParserM a) where
p <+> q = Parser (\s => parse p s ++ parse q s)
instance Monoid (ParserM a) where
neutral = Parser (const [])
instance VerifiedSemigroup (ParserM a) where
semigroupOpIsAssociative (Parser p) (Parser q) (Parser r) = ?whatGoesHere
I'm basically stuck after intros
, with the following prover state:
-Parser.whatGoesHere> intros
---------- Other goals: ----------
{hole3},{hole2},{hole1},{hole0}
---------- Assumptions: ----------
a : Type
p : String -> List (a, String)
q : String -> List (a, String)
r : String -> List (a, String)
---------- Goal: ----------
{hole4} : Parser (\s => p s ++ q s ++ r s) =
Parser (\s => (p s ++ q s) ++ r s)
-Parser.whatGoesHere>
It looks like I should be able to use rewrite
together with appendAssociative
somehow,
but I don't know how to "get inside" the lambda \s
.
Anyway, I'm stuck on the theorem-proving part of the exercise - and I can't seem to find much Idris-centric theorem proving documentation. I guess maybe I need to start looking at Agda tutorials (though Idris is the dependently-typed language I'm convinced I want to learn!).
funext : (f, g : a -> b) -> ((x : a) -> f x = g x) -> f = g
). Sadly neither Agda nor Idris (as far as I know) are unable to prove this statement, so it must be assumed as an axiom. The other option is to introduce your own notion of equality (e.g.p = q <=> forall s. parse p s = parse q s
), but I don't think Idris'sVerifiedSemigroup
is equipped to deal with custom equality. – Vitusfunext = believe me
seems like cheating - then again, it's not like I need a rigorous proof for a toy problem that, in my past attempts in other languages, would have any kind of proof only in comments if at all. – h.forrest.alexander