Skip to content

Instantly share code, notes, and snippets.

@witt3rd
Created October 1, 2020 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save witt3rd/68f45c90c904dd350a299bc99f94fc91 to your computer and use it in GitHub Desktop.
Save witt3rd/68f45c90c904dd350a299bc99f94fc91 to your computer and use it in GitHub Desktop.
record Foo where
constructor MkFoo
from : Type
to : Type
bar : (a : Foo) -> (x : from a) -> (to a)
-- impl not important
baz : (a : Foo) -> (b : Foo) -> ((to b) = (from a)) => (x: from b) -> (to a)
baz a b x = do
let y = bar b x
-- ?hole
let z = bar a y
z
{-
When checking argument x to Main.bar:
Type mismatch between
to b (Type of y)
and
from a (Expected type)
-}
{-
a : Foo
b : Foo
x : from b
constraint : to b = from a
y : to b
--------------------------------------
hole : to a
-}
@MarcelineVQ
Copy link

baz : (a : Foo) -> (b : Foo) -> a = b -> Foo.to b = Foo.from a -> (x : from b) -> to a
baz a b prf1 prf2 x =
  let y = bar b x
  in bar a (rewrite sym prf2 in y)

@witt3rd
Copy link
Author

witt3rd commented Oct 1, 2020

foo1 : Foo
foo1 = MkFoo String Nat

foo2 : Foo
foo2 = MkFoo Nat Int

test : Nat
test = baz foo2 foo1

{-
Type mismatch between
        (a = b) -> (to b = from a) -> from b -> to a (Type of baz a b)
and
        Nat (Expected type)
-}

@MarcelineVQ
Copy link

baz : (a : Foo) -> (b : Foo) -> (prf : Foo.to b = Foo.from a) => (x : from b) => to a
baz a b =
  let y = bar b x
  in bar a (rewrite sym prf in y)

@witt3rd
Copy link
Author

witt3rd commented Oct 1, 2020

Working Version

record Foo where
  constructor MkFoo
  from : Type
  to : Type

bar : (a : Foo) -> (x : from a) -> (to a)
-- impl not important

baz : (a : Foo) -> (b : Foo) -> (from a = to b) -> (x : from b) -> to a
baz a b prf x =
  let y = bar b x
  in bar a (rewrite prf in y)

foo1 : Foo
foo1 = MkFoo String Nat

foo2 : Foo
foo2 = MkFoo Nat Int

test : Int
test = baz foo2 foo1 %implementation "test"

@MarcelineVQ
Copy link

MarcelineVQ commented Oct 1, 2020

record Foo where
  constructor MkFoo
  from : Type
  to : Type

bar : (a : Foo) -> (x : from a) -> (to a)
-- impl not important

baz : (a : Foo) -> (b : Foo) -> (prf : Foo.to b = Foo.from a) => (x : from b) => to a
baz a b =
  let y = bar b x
  in bar a (rewrite sym prf in y)

foo1 : Foo
foo1 = MkFoo Nat String

foo2 : Foo
foo2 = MkFoo String Int

test : Int
test = baz foo2 foo1

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