brendanzab / rusp

A minimal scripting and data language for Rust.
Apache License 2.0
16 stars 3 forks source link

Pattern matching on types #17

Open Aatch opened 11 years ago

Aatch commented 11 years ago

Since we seem to be going for dynamic, strong typing, it would be nice to have a way to pattern match on types. This should just be another pattern, so it can be used anywhere patterns can be used.

I'm not sure of the exact syntax here, since just doing (match val ((a int) (do_stuff))) would conflict with structure matching. I am leaning towards having: (match val (a:int (do_stuff))), which would match that arm if val is an integer type.

I haven't thought too hard about any potential issues involved with this.

huonw commented 11 years ago

I'm not sure about not using s-exprs for this. Maybe (: a int), like typed racket would be more consistent, although this probably also interacts poorly with pattern matching. That said, the current pattern matching syntax is extremely ad-hoc and could/should be improved.