0

I'm having difficulty implementing Applicative for my type. Here's Functor

data Connection : repr -> out -> Type where
  MkConnection : (repr -> ty) -> (ty -> out) -> Connection repr out

Functor (Connection repr) where
  map f (MkConnection get g) = MkConnection get $ f . g

If I write Applicative with a hole

Applicative (Connection repr) where
  pure x = ?rhs

I can type check to get

"src/Foo.idr" 94L, 4210C written
 0 a : Type
 0 repr : repr
   x : a
------------------------------
rhs : Connection repr a

A search gives no results. Indeed, if I add more detail

Applicative (Connection repr) where
  pure x = MkConnection ?get ?g

I get

"src/Foo.idr" 94L, 4223C written
Error: While processing right hand side of pure. When unifying Connection repr a and Connection repr a.
Mismatch between: Type and repr (implicitly bound at .../src/Foo.idr:94:5--94:34).

.../src/Foo.idr:94:14--94:34
    |
 94 |     pure x = MkConnection ?get ?g
    | 

I would have thought I can implement that with

pure x = MkConnection (\r => ()) (\_ => x)

but I'm getting

"src/Foo.idr" 94L, 4235C written
Error: While processing right hand side of pure. When unifying Connection repr a and Connection repr a.
Mismatch between: Type and repr (implicitly bound at .../src/Foo.idr:94:5--94:47).

.../src/Foo.idr:94:14--94:47
    |
 94 |     pure x = MkConnection (\r => ()) (\_ => x)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It seems to be interpreting \r => () as a Type -> something

joel
  • 6,359
  • 2
  • 30
  • 55

0 Answers0