I just decided on this syntax for match-case:
if <expr> is
<pat> then <expr>,
<pat> then <expr>,
else <expr>
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
interesting, could you maybe give a few concrete examples to demonstrate to help grok?
https://dl.acm.org/doi/pdf/10.1145/3689746 inspired from this
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>
This only replaces match-with with if-is
concatString = \s :: string | list string:
if s is
xs :: list then insert `+` xs,
x :: string then x;
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;
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