Definition of categories in Idris

I'm trying to define checked categories internal to Idris types, but my approach doesn't print the check.

class Cat ob (mor : ob -> ob -> Type) where 
  comp  : {a : ob} -> {b : ob} -> {c : ob} -> mor a b -> mor b c -> mor a c
  unit   : (a : ob) -> mor a a
  l     : {a,b : ob} -> {f : mor a b} -> (comp (unit a) f) = f

      

ob

- type of objects, mor a b

- type of morphisms from a

to b

. There are still correct laws on unity and associativity, but already my definition for l

does not work. It says:

 When elaborating type of constructor of Main.Cat:
 When elaborating an application of comp:
         Can't unify
                 mor a13 b14 (Type of f)
         with
                 mor b14 c (Expected type)

      

I find this confusing. unit a

has a type mor a a

, f

has a type mor a b

, why comp (unit a) f

not has a type mor a b

?

+3


source to share


1 answer


It only works if I explicitly give implicit parameters:

class Cat ob (mor : ob -> ob -> Type) where
  comp  : {a : ob} -> {b : ob} -> {c : ob} -> mor a b -> mor b c -> mor a c
  unit  : (a : ob) -> mor a a
  l     : {a,b : ob} -> {f : mor a b} -> (comp {a=a} {b=a} {c=b} (unit a) f) = f

      



Edwin Brady points out this problem why. The reason is that there is no mor a b

and mor b c

no restriction on actually the same type. For example, it mor

can be a permanent function. In this case, type checking cannot infer a

and b

only from mor a b

, which results in an error message.

If someone was to limit that mor

- injective function (as it is likely to be made in the future for the class argument), it was possible to make a conclusion a

and b

and no longer need to give arguments implicitly.

+3


source







All Articles