Original-Via: uk.ac.nsf; Mon, 4 Nov 91 17:00:37 GMT
> Kent Karlsson asks:
> | Which semantics did you use?
>
> The following seemed sensible to me (Your first choice in each case):
There was no ranking!
>
> For p+k patterns: (as in the report):
> case e0 of {p+k -> e; _ -> e'}
> = if e0 >= k then let {p = e0-k} in e else e'
>
> For c*p patterns:
> case e0 of {c*p -> e; _ -> e'}
> = if e0 >= 0 && e0 `rem` c == 0
> then let {p = e0 `div` c} in e
> else e'
>
I had hoped not, since then a match can fail and fail the entier program,
even if a "later" patterns really matches, since in the above the "next"
pattern is not tested upon such a fail. The ones I had hoped for was
one of the two last alternatives in each case (no ranking claimed among
these alternatives):
case e0 of {p+k -> e; _ -> e'}
either = if e0 >= k then case e0-k of {p -> e; _ -> e'} else e'
or = case e0-k of {p -> e; _ -> e'}
case e0 of {c*p -> e; _ -> e'}
either = if e0 >= 0 then case e0 `divRem` c of (p, 0) -> e; _ -> e'} else e'
or = case e0 `divRem` c of (p, 0) -> e; _ -> e'}
Here the "ensuing" patterns are given "a chance" to match, even if the
pattern (p) did not match after the subtraction/division.
/kent k