[Haskell] Syntax Q: How do you share RHS's in case expressions!?

Ben Rudiak-Gould Benjamin.Rudiak-Gould at cl.cam.ac.uk
Fri Oct 22 12:15:16 EDT 2004


Ryan Newton wrote:

>  For example, in OCaml:
>
>  match 3 with 3 -> 99 | 4 -> 99
>
>  Can be abbreviated
>
>  match 3 with 3 | 4 -> 99
>
>  But I have had no luck figuring out how to do the same thing with:
>
>  case 3 of 3 -> 99; 4 -> 99

You can do this:

   let rhs = (some complicated expression) in
   case 3 of
     3 -> rhs
     4 -> rhs

The complicated expression won't be evaluated unless one of the 
appropriate case alternatives is chosen.

-- Ben



More information about the Haskell mailing list