Hello. The compiler gives here correct message. Because your messageParam can be anything of type Message. Lodash(_) in Elm means the same. So it means anything with type Message. That’s why you have two same branches. And Elm compiler tells you about it.
Best, Andrey > On 10 Jul 2017, at 20:11, Patrick Stubner <[email protected]> wrote: > > I haven't really used Elm that much, but you may want something like this: > > > module Main exposing (..) > > import Html exposing (Html, text, div) > > type Message = Good | Bad | ManyOthers > > type alias Node = { message : Message } > > trymatch : Node -> Message -> Bool > trymatch node messageParam = > node.message == messageParam > > evalTrue = trymatch { message = Good } Good > evalFalse = trymatch { message = Good } Bad > > main : Html a > main = > div [] > [ text (toString evalTrue) > , text " / " > , text (toString evalFalse)] > > > You can try it out in https://ellie-app.com > > P@ > > > Am Sonntag, 9. Juli 2017 22:55:27 UTC+2 schrieb jadski: > 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. > > > -- > 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 [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <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 [email protected]. For more options, visit https://groups.google.com/d/optout.
