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

Default interface resolution with parametric types is odd #4598

Open
berewt opened this issue Nov 25, 2018 · 0 comments
Open

Default interface resolution with parametric types is odd #4598

berewt opened this issue Nov 25, 2018 · 0 comments

Comments

@berewt
Copy link

berewt commented Nov 25, 2018

I was investigating down the path suggested by Ahmad and Edwin in issue #4279. After a few tries, it looks like Superclass default implementation behaviour is weird when you use parametric types:

Steps to reproduce

Try to compile the following file:

module Main

import Data.Vect

interface Enumerated (t : Type) (len : Nat) | t where
  toFin  : t -> Fin len

data FooBar = Foo

implementation Enumerated FooBar 1 where
  toFin Foo = FZ

interface (Eq t, Ord t) => EnumeratedDerivation t (len : Nat) | t where
  implementation Eq t where
    x == y = myFin x == myFin y
  implementation Ord t where
    compare x y = compare (myFin x) (myFin y)
    x > y = (myFin x) > (myFin y)
    x < y = (myFin x) < (myFin y)
    x >= y = (myFin x) >= (myFin y)
    x <= y = (myFin x) <= (myFin y)

  myFin : t -> Fin len

{- This one works:
implementation EnumeratedDerivation FooBar 1 where
  myFin = toFin
-}


-- This one fails
implementation Enumerated t len => EnumeratedDerivation t len where
  myFin = toFin

Observed behavior

34 | implementation Enumerated t len => EnumeratedDerivation t len where
   |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When checking right hand side of Main.t, len implementation of Main.EnumeratedDerivation with expected type
        EnumeratedDerivation t len

Can't find implementation for Ord t

Expected behavior

I think it should compile, but anyhow, it shouldn't claim that the superinterface implementation can't be found while we can provide a default implementation.

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

No branches or pull requests

1 participant