Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit coercion whose type is not in normal form ignored #4206

Open
gallais opened this issue Nov 20, 2017 · 1 comment
Open

Implicit coercion whose type is not in normal form ignored #4206

gallais opened this issue Nov 20, 2017 · 1 comment

Comments

@gallais
Copy link
Member

gallais commented Nov 20, 2017

I'm using a bunch of type-level combinators to deal with indexed types without explicitly plumbing the index everywhere. I'm also using an implicit coercion to automatically wrap some indexed values in a record wherever the expected type and the type of the expression I give don't match up.

Declaring an implicit with the type All (Vec a :-> Wrap (Vec a)) leads to argh being rejected with the error:

BugReport.idr:31:10-11:When checking right hand side of argh with expected type
        Wrap (Vec a) n

Type mismatch between
        Vec a n (Type of k)
and
        Wrap (Vec a) n (Expected type)

Manually normalising the type of wrapVec to Vec a n -> Wrap (Vec a) n solves the issue.

module BugReport

%default total
%access public export

-- Indexed arrows
infixr 1 :->
(:->) : (a, b : i -> Type) -> (i -> Type)
(:->) a b i = a i -> b i

-- Universal quantifier
All : (a : i -> Type) -> Type
All {i} a = {i : i} -> a i

-- An example of a Nat-indexed family
data Vec : Type -> Nat -> Type where
  Nil  : Vec a Z
  Cons : a -> Vec a n -> Vec a (S n)

-- The type of wrappers for Nat-indexed families
record Wrap (A : Nat -> Type) (n : Nat) where
  constructor MkWrap
  UnWrap : A n

-- Implicit coercion from vecs to wrapped vecs
implicit wrapVec : All (Vec a :-> Wrap (Vec a))
wrapVec = MkWrap

{- solution:
implicit wrapVec : Vec a n -> Wrap (Vec a) n
wrapVec = MkWrap
-}

argh : Vec a n -> Wrap (Vec a) n
argh k = k

I'd expect Idris to do the normalisation of the implicit's type itself.

gallais added a commit to gallais/idris-tparsec that referenced this issue Nov 20, 2017
@ahmadsalim
Copy link

Thanks for reporting the issue.
Unfortunately, I am not very familiar with implicit resolution myself.

Maybe @edwinb has an idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants