[Bro-Dev] Pattern matching for the Bro language

Matthias Vallentin vallentin at icir.org
Wed Aug 19 13:15:56 PDT 2015


> >       local result = switch( x )
> >         {
> >         case T:
> >         case U:
> >         };
> 
> Personally, this strike me as a tad weird, since now "result" might not
> have a statically determined type, so we're back to it being "any".

To avoid falling back to "any land," the additional constraint in this
case would be that each case block would have to have a return statement
with the same type. 

The use case I had in mind is returning from a function.

    function f(x: any) : string
        {
        return switch(x)
            {
            case T:
                return "T";
            case U:
                return "U";
            }
        }

Though that's simply syntactic sugar for:

    function f(x: any) : string
        {
        local result = "";
        switch(x)
            {
            case T:
                result = "T";
            case U:
                result = "U";
            }
        return result;
        }

I'm not feeling very strong about it.

    Matthias


More information about the bro-dev mailing list