[Haskell-cafe] Problem about pattern matching.

Henning Thielemann schlepptop at henning-thielemann.de
Wed Apr 28 13:51:46 EDT 2010

minh thu schrieb:
> 2010/4/28 Magicloud Magiclouds <magicloud.magiclouds at gmail.com>:
>> Hi, I have code as below. How come "case" version works wrong and
>> gives me "overlap" compiling warning? Thanks.
>>  if dayOfMonth == firstDayOfMonth
>>    then v day (x, y)
>>    else if dayOfMonth == lastDayOfMonth
>>      then not_ $ v day (x, y)
>>      else Mider day (x, y)
>>  case dayOfMonth of
>>    firstDayOfMonth -> v day (x, y)
>>    lastDay -> not_ $ v day (x, y)
>>    _ -> Mider day (x, y)
> Hi,
> firstDayIfMonth and lastDay are new variables, not previously bound
> variable. This means that trying to pattern match (the value of)
> dayOfMonth will always succeed with the first alternative.

You can however simulate a 'case' with predefined variables:

More information about the Haskell-Cafe mailing list