AlgebraicJulia / Catlab.jl

A framework for applied category theory in the Julia language
https://www.algebraicjulia.org
MIT License
609 stars 57 forks source link

Error handling in `@syntax` #135

Open jpfairbanks opened 4 years ago

jpfairbanks commented 4 years ago

I just spent waay too long debugging a new syntax I made.

MWE:

@theory BiproductCategory(Ob, Hom) => Epidemiology(Ob, Hom) begin
    spontaneous(A::Ob, B::Ob)::Hom(A,B)
end

@syntax FreeEpidemiology(ObExpr, HomExpr) begin
    compose(f::Hom, g::Hom) = associate(new(f,g; strict=true))
end

Error:

LoadError: ArgumentError: invalid type for argument A in method definition for otimes at

This error did not point me at the problem at all. The correct syntax is:

@theory BiproductCategory(Ob, Hom) => Epidemiology(Ob, Hom) begin
    spontaneous(A::Ob, B::Ob)::Hom(A,B)
end

@syntax FreeEpidemiology(ObExpr, HomExpr) Epidemiology begin
    compose(f::Hom, g::Hom) = associate(new(f,g; strict=true))
end

I think the solution is for the macro @syntax to check that you gave it the name of a valid Theory before it continues to execute. The error should say something like No Theory or Signature was provided to the@syntax` macro.

epatters commented 4 years ago

OK, that's pretty bad.

jpfairbanks commented 3 years ago

This error has gotten better, but still doesn't check the right thing

julia> @theory BiproductCategory{Ob, Hom} <: Epidemiology{Ob, Hom} begin
           spontaneous(A::Ob, B::Ob)::Hom(A,B)
       end

julia> @syntax FreeEpidemiology{ObExpr, HomExpr} begin
           compose(f::Hom, g::Hom) = associate(new(f,g; strict=true))
       end
ERROR: ArgumentError: invalid type for argument f in method definition for compose at REPL[9]:2
Stacktrace:
 [1] top-level scope
   @ REPL[9]:2