Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

case syntax

0 views
Skip to first unread message

Geoffrey Irving

unread,
May 6, 2011, 12:12:12 AM5/6/11
to Dylan Simon, duck...@googlegroups.com
I seem to have entirely forgotten about our generalized case syntax,
which now strikes me as weird. If you remember it, could you explain
it to me? Here's the example from test/basic.duck:

full x = case
x of [y] case y of
[z] -> 1
[] -> 2
_ case False -> 3
head x of
[1] -> 3
[y] case
y > 0 -> 4
True -> 5
_ case x of _ -> 6

Geoffrey

Dylan Simon

unread,
May 6, 2011, 12:25:11 AM5/6/11
to duck...@googlegroups.com
From Geoffrey Irving <irv...@naml.us>, Thu, May 05, 2011 at 09:12:12PM -0700:

We're using case for both actual case and pattern guards, and allowing
branches at every level. That was a purposefully convoluted example, but
translated into haskell, it means:

full x = case x of
[y]

| [z] <- y -> 1
| [] <- y -> 2
| _ <- y, False -> 3
_ -> case head x of
[1] -> 3
[y]


| y > 0 -> 4
| True -> 5

_ | _ <- x -> 6

To me, the only slightly strange part is the "else" syntax (line starting
"head x of"), but I think it looks fine in normal use:

case
x of 4 -> 0
y of 6 -> 1
z of 8 -> 2
_ -> 3

Reply all
Reply to author
Forward
0 new messages