This code compiles with an error: this pattern match clause is redundant
But this code is like the example in the book. What led to this code was
when the second case “idle” was missing, things behaved like the the first
case “transacting” evaluated true no matter what s.ps was. So I added the
second case just to debug that, and got the compile error, which kind of
confirms it is always matching.
fun isWeekday
(x: wday): bool = case x of
| Saturday() => false | Sunday() => false | _ => true
// end of [isWeekday]
CODE
datatype pstate =
| Idle of ()
| Transacting of ()
| Hang of ()
typedef state = @{ addr= uint8, ps= pstate }
fun process (c:int, s:state) : state = let
val sn = case 0 of
| _ when ch = ‘p’ => let
val i:int = case s.ps of
| transacting => let
val _ = i2c_stop()
in 1 end
| idle => let
val _ = i2c_start()
in 2 end
val () = print! i
in @{ addr = s.addr, ps = idle } end
ThanksOn Sunday, September 27, 2015 at 11:01:33 AM UTC-6, gmhwxi wrote:
If a nullary constructor Foo is used as a pattern, it needs to be
written as ‘Foo()’; ‘Foo’ is considered a variable when used as a pattern.
On Sun, Sep 27, 2015 at 12:54 PM, Mike Jones <pro...@gmail.com <javascript:>> wrote:
This code compiles with an error: this pattern match clause is
redundant
But this code is like the example in the book. What led to this code was
when the second case “idle” was missing, things behaved like the the first
case “transacting” evaluated true no matter what s.ps was. So I added
the second case just to debug that, and got the compile error, which kind
of confirms it is always matching.
fun isWeekday
(x: wday): bool = case x of
| Saturday() => false | Sunday() => false | _ => true
// end of [isWeekday]
CODE
datatype pstate =
| Idle of ()
| Transacting of ()
| Hang of ()
typedef state = @{ addr= uint8, ps= pstate }
fun process (c:int, s:state) : state = let
val sn = case 0 of
| _ when ch = ‘p’ => let
val i:int = case s.ps of
| transacting => let
val _ = i2c_stop()
in 1 end
| idle => let
val _ = i2c_start()
in 2 end
val () = print! i
in @{ addr = s.addr, ps = idle } end
Unlike using ‘=’ for ‘==’ in C, using ‘Foo’ for ‘Foo()’ causes no trouble:
If ‘Foo’ is the pattern for the last clause, then ‘Foo()’ and ‘Foo’ are
really the same (assuming pattern matching is exhaustive)
If ‘Foo’ is not the last one, then you always get a compilation error.On Sunday, September 27, 2015 at 3:00:48 PM UTC-4, Mike Jones wrote:
I will store that one next to:
if (i = j)
{
be_subtle_ and_cause_trouble();
}
Solved problem…
Thanks
On Sunday, September 27, 2015 at 11:01:33 AM UTC-6, gmhwxi wrote:
If a nullary constructor Foo is used as a pattern, it needs to be
written as ‘Foo()’; ‘Foo’ is considered a variable when used as a pattern.
On Sun, Sep 27, 2015 at 12:54 PM, Mike Jones pro...@gmail.com wrote:
This code compiles with an error: this pattern match clause is
redundant
But this code is like the example in the book. What led to this code was
when the second case “idle” was missing, things behaved like the the first
case “transacting” evaluated true no matter what s.ps was. So I added
the second case just to debug that, and got the compile error, which kind
of confirms it is always matching.
fun isWeekday
(x: wday): bool = case x of
| Saturday() => false | Sunday() => false | _ => true
// end of [isWeekday]
CODE
datatype pstate =
| Idle of ()
| Transacting of ()
| Hang of ()
typedef state = @{ addr= uint8, ps= pstate }
fun process (c:int, s:state) : state = let
val sn = case 0 of
| _ when ch = ‘p’ => let
val i:int = case s.ps of
| transacting => let
val _ = i2c_stop()
in 1 end
| idle => let
val _ = i2c_start()
in 2 end
val () = print! i
in @{ addr = s.addr, ps = idle } end
If a nullary constructor Foo is used as a pattern, it needs to be
written as ‘Foo()’; ‘Foo’ is considered a variable when used as a pattern.On Sun, Sep 27, 2015 at 12:54 PM, Mike Jones proc...@gmail.com wrote:
This code compiles with an error: this pattern match clause is redundant
But this code is like the example in the book. What led to this code was
when the second case “idle” was missing, things behaved like the the first
case “transacting” evaluated true no matter what s.ps was. So I added the
second case just to debug that, and got the compile error, which kind of
confirms it is always matching.
fun isWeekday
(x: wday): bool = case x of
| Saturday() => false | Sunday() => false | _ => true
// end of [isWeekday]
CODE
datatype pstate =
| Idle of ()
| Transacting of ()
| Hang of ()
typedef state = @{ addr= uint8, ps= pstate }
fun process (c:int, s:state) : state = let
val sn = case 0 of
| _ when ch = ‘p’ => let
val i:int = case s.ps of
| transacting => let
val _ = i2c_stop()
in 1 end
| idle => let
val _ = i2c_start()
in 2 end
val () = print! i
in @{ addr = s.addr, ps = idle } end