Pattern matching compile failure

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

I will store that one next to:

if (i = j)
{
be_subtle_ and_cause_trouble();
}

Solved problem…

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


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com?utm_medium=email&utm_source=footer
.

Unlike using ‘=’ for ‘==’ in C, using ‘Foo’ for ‘Foo()’ causes no trouble:

  1. If ‘Foo’ is the pattern for the last clause, then ‘Foo()’ and ‘Foo’ are
    really the same (assuming pattern matching is exhaustive)
  2. 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


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com?utm_medium=email&utm_source=footer
.

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


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/4176c280-dd32-4328-9f92-96b9d61f6e53%40googlegroups.com?utm_medium=email&utm_source=footer
.