I'm trying to implement the simplest profunctor optic in Idris. Iso is a function that is supposed to be polymorphic in all profunctors. I think that's the correct syntax.
Everything type-checks, except for the final test.
interface Profunctor (p : Type -> Type -> Type) where
dimap : (a' -> a) -> (b -> b') -> p a b -> p a' b'
Iso : Type -> Type -> Type -> Type -> Type
Iso a b s t = {p : Type -> Type -> Type} -> Profunctor p => p a b -> p s t
-- A pair of functions
data PairFun : Type -> Type -> Type -> Type -> Type where
MkPair : (s -> a) -> (b -> t) -> PairFun a b s t
-- PairFun a b s t is a Profunctor in s t
Profunctor (PairFun a b) where
dimap f g (MkPair get set) = MkPair (get . f) (g . set)
-- Extract a pair of functions from an Iso
fromIso : Iso a b s t -> PairFun a b s t
fromIso iso = iso (MkPair id id)
-- Turn a pair of functions to an Iso
toIso : PairFun a b s t -> Iso a b s t
toIso (MkPair get set) = dimap get set
-- forall p. Profunctor p => p Int Int -> p Char String
myIso : Iso Int Int Char String
myIso = toIso (MkPair ord show)
x : PairFun Int Int Char String
x = fromIso myIso
I'm getting this error. It looks like Idris is complaining about the assumption that p1 is a Profunctor, but that's the constraint in the definition of Iso.
Can't find implementation for Profunctor p1
Type mismatch between
p1 Int Int -> p1 Char String (Type of myIso p1
constraint)
and
p Int Int -> p Char String (Expected type)
Specifically:
Type mismatch between
p1 Int Int
and
p Int Int