jadski
2017-07-09 20:55:27 UTC
Hi, I am getting a compiler error that does not make sense to me - can
anyone help to explain why this fails to compile?
The following code:
<code>
type Message = Good | Bad | ManyOthers
type alias Node = { message : Message }
trymatch : Node -> Message -> Bool
trymatch node messageParam =
case node.message of
messageParam ->
True
_ ->
False
evalTrue = trymatch { message = Good } Good
evalFalse = trymatch { message = Good } Bad
</code>
Generates this compilation error:
<code>
The following pattern is redundant. Remove it.
10| _ ->
^
Any value with this shape will be handled by a previous pattern.
</code>
However node.message and messageParam can clearly be different, as in
evalFalse.
Hence the message "Any value with this shape will be handled by a previous
pattern." appears incorrect, and is confusing me.
A helpful slacker suggested using "if node.message == messageParam then",
which compiles, but doesn't clarify what's going wrong here.
anyone help to explain why this fails to compile?
The following code:
<code>
type Message = Good | Bad | ManyOthers
type alias Node = { message : Message }
trymatch : Node -> Message -> Bool
trymatch node messageParam =
case node.message of
messageParam ->
True
_ ->
False
evalTrue = trymatch { message = Good } Good
evalFalse = trymatch { message = Good } Bad
</code>
Generates this compilation error:
<code>
The following pattern is redundant. Remove it.
10| _ ->
^
Any value with this shape will be handled by a previous pattern.
</code>
However node.message and messageParam can clearly be different, as in
evalFalse.
Hence the message "Any value with this shape will be handled by a previous
pattern." appears incorrect, and is confusing me.
A helpful slacker suggested using "if node.message == messageParam then",
which compiles, but doesn't clarify what's going wrong here.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.