ZVON > References > Haskell reference
| Indexes | >> Syntax << | Prelude | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Name case expressions
Description A case expression must have at least one alternative and each alternative must have at least one body. Each body must have the same type, and the type of the whole expression is that type.
Related:
Bibliography: Case Expressions [ A Gentle Introduction to Haskell ]

Example 1

Input: case 2 of { (1) -> "A"; (2) -> "B"; (3) -> "C" }

Output: "B"

Example 2
Program source: 

aaa x = case x of 
             1 ->  "A"
             2 ->  "B"
             3 ->  "C"

Input: aaa 3

Output: "C"

Example 3
Program source: 

aaa x = case x of 
             []     ->  [1]
             [x]    ->  [x]
             (x:xs) ->  xs

Input: aaa [1,2,3]

Output: [2,3]

Input: aaa []

Output: [1]

Input: aaa [4]

Output: [4]