Stream: cull-os

Topic: Match syntax


view this post on Zulip RGBCube (Oct 13 2024 at 08:23):

I just decided on this syntax for match-case:

if <expr> is
  <pat> then <expr>,
  <pat> then <expr>,
  else <expr>

view this post on Zulip RGBCube (Oct 13 2024 at 08:26):

Since patterns will be able to have expressions in them for things like type checking (<pat> :: <expr>, same as just <pat> but with and <expr>.check <pat-bind>) and conditionals <pat> and <expr> you won't need to hard code an if into the match-case

view this post on Zulip Tim DeHerrera (Oct 13 2024 at 14:30):

interesting, could you maybe give a few concrete examples to demonstrate to help grok?

view this post on Zulip RGBCube (Oct 14 2024 at 04:33):

https://dl.acm.org/doi/pdf/10.1145/3689746 inspired from this

view this post on Zulip RGBCube (Oct 14 2024 at 04:35):

I was thinking of this earlier but I hadn't thought of using a different keyword after if to do a match. My initial idea was just

match <expr> with
  <pat> then <expr>,
  <pat> then <expr>,
  else <expr>

view this post on Zulip RGBCube (Oct 14 2024 at 04:35):

This only replaces match-with with if-is

view this post on Zulip RGBCube (Oct 14 2024 at 04:37):

concatString = \s :: string | list string:
  if s is
    xs :: list then insert `+` xs,
    x :: string then x;

view this post on Zulip RGBCube (Oct 14 2024 at 05:00):

insert = \f: \xs :: list:
  if xs is
    [] then throw "cannot insert with zero items",
    [x] then x,
    [x] ++ xs then f x $ insert xs;

toString = \x:
  if x is
    s :: string then s,
    n :: number then numberToString n,
    xs :: list then insert `+` $ map toString xs;

view this post on Zulip RGBCube (Oct 26 2024 at 19:52):

Update on this: if is won't have else, as that's a duplicate of _ then at the end (like in Rust)


Last updated: Nov 21 2024 at 09:45 UTC