I'd like to create a function with type constrained by an interface. My intention is to build a simple monoid solver using VerifiedMonoid
defined inClasses.Verified
module from contrib package.
Idris gives me the following error:
Monoid-prover.idr line 29 col 5:
When checking type of MonoidProver.eval:
Can't find implementation for VerifiedMonoid a
for the type signature of eval
:
eval : VerifiedMonoid a => Expr n -> Env a n -> a
Am I doing something silly or missing something? Such constrained types (like eval's type) can be interpreted like Haskell's types?
The complete code is shown below.
module MonoidProver
import Classes.Verified
import Data.Fin
import Data.Vect
%default total
infixl 5 :+:
data Expr : Nat -> Type where
Var : Fin n -> Expr n
Id : Expr n
(:+:) : Expr n -> Expr n -> Expr n
Env : VerifiedMonoid a => (a : Type) -> Nat -> Type
Env a n = Vect n a
eval : VerifiedMonoid a => Expr n -> Env a n -> a
eval (Var i) env = index i env
eval Id env = neutral
eval (e :+: e') env = eval e env <+> eval e' env
Env
scopesa
wrongly: I think the type you've given is equivalent toEnv : VerifiedMonoid a => (b : Type) -> Nat -> Type
. Also, what does theVerifiedMonoid
constraint onEnv
supposed to buy you? If you remove it fromEnv
's signature, your code typechecks. – Cactus