Skip to content

Commit

Permalink
change when syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTaelin committed Nov 1, 2024
1 parent d982572 commit bd797a0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Kind/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ parseIf = withSrc $ do
-- When
-- ----

-- when fn x { c0: v0 c1: v1 _: df }
-- when fn x { c0: v0 c1: v1 } else { df }
-- -------------------------------------------------------- desugars to
-- if (fn x c0) { v0 } else if (fn x c1) { v1 } else { df }

Expand All @@ -985,22 +985,20 @@ parseWhen = withSrc $ do
val <- parseTerm
char_skp '{'
cases <- P.many $ do
P.notFollowedBy (char_skp '_')
cond <- parseTerm
char_skp ':'
body <- parseTerm
return (cond, body)
defaultCase <- do
char_skp '_'
char_skp ':'
body <- parseTerm
return $ body
char_skp '}'
string_skp "else"
char_skp '{'
elseCase <- parseTerm
char '}'
return $ foldr
(\ (cond, body) acc -> App
(Mat [("True", body), ("False", acc)])
(App (App fun val) cond))
defaultCase
elseCase
cases

-- Match
Expand Down

0 comments on commit bd797a0

Please sign in to comment.