[Haskell-beginners] do not understand Semantics of Case Expressions in report

Michael Mekhanoshin mmexanosh at gmail.com
Tue Oct 21 13:35:46 EDT 2008


2008/10/21 John Dorsey <haskell at colquitt.org>:
>  It looks like
>
>   "case e' of { y -> ..."
>
> was introduced solely to give e' a name that can be used in two places,
> since the nested form may fail to match at each level.  It seems to me
> that without this, you could get code explosion from duplicating the
> expression e' below; with this you get sharing.
...
>
> -- Match v against a constructor with multiple fields
> case v  of {  K  { f1  =  p1  ,  f2  =  p2  ,  ... } ->  e ; _ ->  e'  }
>
> -- Same, but introduce y to represent e' without loss of sharing
> case e' of { y ->
>     case  v  of {  K  { f1  =  p1  ,  f2  =  p2  ,  ... } ->  e ; _ ->  y  }}
>
> I hope this helps.
>
Surely it does.
Most tricky part here (for me) is that e' goes in outer scope. It
works here like in rule (c) . I got it. Thank you for your help.

Regards,
Michael


More information about the Beginners mailing list