Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InterTypes variants referring to locally defined variants #87

Closed
p-stokes opened this issue Dec 4, 2023 · 2 comments
Closed

InterTypes variants referring to locally defined variants #87

p-stokes opened this issue Dec 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@p-stokes
Copy link
Contributor

p-stokes commented Dec 4, 2023

It might be useful to be able to define recursive sum types in InterTypes. Currently, the below example is not possible.

@sum Var begin
  Untyped(var::Symbol)
  Typed(var::Symbol, type::Symbol)
end

@sum UWDTerm begin
  Statement(relation::Symbol, variables::Vector{Var})
  UWDExpr(context::Vector{Var}, statements::Vector{Statement})
  UWDModel(header::String, uwd::UWDExpr)
end
@p-stokes p-stokes added the enhancement New feature or request label Dec 4, 2023
@jpfairbanks jpfairbanks added bug Something isn't working and removed enhancement New feature or request labels Dec 4, 2023
@jpfairbanks jpfairbanks changed the title can't define recursive sum types in InterTypes InterTypes variants referring to locally defined variants Dec 4, 2023
@jpfairbanks
Copy link
Member

The problem isn't the recursion. The following test case shows recursion support

@sum Const begin
  ConstStr(val::String)
  ConstInt(val::Int32)
  ConstBool(val::Bool)
end

@sum Term begin
  Constant(val::Const)
  Plus(terms::Vector{Term})
  IfThenElse(ifcase::Term, thencase::Term, elsecase::Term)
end

struct Assignment
  lhs::String
  rhs::Term
end

The problem is that a sum type variant can't refer to a previous variant. I identified that by deleting parts of the following code until it worked.

@sum UWDTerm begin
  Statement(relation::Symbol, variables::Vector{Var})
  UWDExpr(context::Vector{Var}, statements::Vector{Statement})
  UWDModel(header::String, uwd::UWDExpr)
end

The problem is that when processing UWDTerm the InterTypes.parse_intertype_decl is looking for a type called Statement which doesn't exist yet.

@olynch, this is a pretty big reason for using the @data macro. We had the ability to write really compact type specifications. You would be able to workaround it as follows. Except that InterTypes doesn't support subtyping relations.

@sum Var begin
  Untyped(var::Symbol)
  Typed(var::Symbol, type::Symbol)
end

struct Statement # <: UWDTerm
  relation::Symbol
  variables::Vector{Var}
end

struct UWDExpr # <: UWDTerm
  context::Vector{Var}
  statements::Vector{Statement}
end

struct UWDModel # <: UWDTerm
  header::String
  uwd::UWDExpr
end

@p-stokes
Copy link
Contributor Author

p-stokes commented Dec 4, 2023

Sorry for the poor phrasing/characterization. Yes, I made the same replacement with UWDTerm and it works in that fashion. I wasn't sure if that was the intended behavior and/or if there might be downstream effects, so I made an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants