Pedantic question about 'case' syntax

9 views
Skip to first unread message

Daniel

unread,
Nov 22, 2011, 1:42:13 AM11/22/11
to Stanford CS240h 2011 Autumn
I have always found 'case' in Haskell to be a bit backwards. From C,
I'm familiar with switch/case, where the 'case' keyword is paired with
the matching option. So in Haskell, it seems to me like the keywords
should be reversed.

When I see:

case x of
Foo a -> z
Bar b -> z'
--other cases

I mentally flip it and read "Of x, case "Foo a" goes to z, case "Bar
b" goes to z', ..."

So, wouldn't a more natural syntax have the word 'case' after the 'x'?
'case' is neither a preposition nor a verb and so seems confusing in
its current position.

How do others read this syntax? I realize this is completely
unimportant once learned, but from a pedagogical point of view I find
this interesting.

Drew Haven

unread,
Nov 22, 2011, 2:12:47 AM11/22/11
to stanford-1...@googlegroups.com
I see what you mean.  It's choosing between many different cases, so either it should be "cases" or each one should be labeled a case.

I read it as, "In the case that X is of type A do B; C do D; ...".
Reply all
Reply to author
Forward
0 new messages