Skip to content

Allow recursive definitions? #15

Closed
@ericphanson

Description

@ericphanson

e.g. @jakobnissen was discussing on #helpdesk how to implement types for regex, and wrote the Rust version would look like

enum Re{
    Empty,
    Class(u8),
    Rep(Box<Re>),
    Alt(Box<Re>, Box<Re>),
    Cat(Box<Re>, Box<Re>),
    Diff(Box<Re>, Box<Re>),
    And(Box<Re>, Box<Re>),
}

I wanted to try with SumTypes, but ran into the fact that you can't have recursive definitions:

julia> using SumTypes

julia> @sum_type Re begin
           Empty()
           Class(::UInt8)
           Rep(::Re)
           Alt(::Re, ::Re)
           Cat(::Re, ::Re)
           Diff(::Re, ::Re)
           And(::Re, ::Re)
       end
ERROR: UndefVarError: Re not defined
Stacktrace:
 [1] top-level scope
   @ ~/.julia/packages/SumTypes/OTmhF/src/SumTypes.jl:92
 [2] top-level scope
   @ REPL[3]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions