Re: [elm-discuss] Re: Pattern matching using existing bound variables
That's exactly Maybe.withDefault "something", which is a great example of partial application. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [elm-discuss] Re: Pattern matching using existing bound variables
Ah, that makes sense. Take the value out of the Maybe box. On Dec 5, 2016 2:32 PM, "David Andrews" wrote: > That is what I meant. I will often use this pattern as follows: > > orSomething : Maybe String -> String > orSomething str = > case str of > Just str -> str > Nothing -> "something" > > I realize, though, that I misunderstood the original question. > > On Monday, December 5, 2016 at 3:25:07 PM UTC-5, Duane Johnson wrote: >> >> >> On Sun, Dec 4, 2016 at 6:53 PM, David Andrews wrote: >> >>> I expect that you are actually looking to do something like this: >>> let >>> x = 1 >>> in >>> case something of >>> Just x -> ... >>> Nothing -> ... >>> >> >> David, are you sure you didn't mean the following? >> >> case something of >> >>Just 1 -> ... >> >>Nothing -> ... >> >> >> It seems strange to include a shadowed variable `x` as in your expected >> code. >> > -- > 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+unsubscr...@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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [elm-discuss] Re: Pattern matching using existing bound variables
That is what I meant. I will often use this pattern as follows: orSomething : Maybe String -> String orSomething str = case str of Just str -> str Nothing -> "something" I realize, though, that I misunderstood the original question. On Monday, December 5, 2016 at 3:25:07 PM UTC-5, Duane Johnson wrote: > > > On Sun, Dec 4, 2016 at 6:53 PM, David Andrews > wrote: > >> I expect that you are actually looking to do something like this: >> let >> x = 1 >> in >> case something of >> Just x -> ... >> Nothing -> ... >> > > David, are you sure you didn't mean the following? > > case something of > >Just 1 -> ... > >Nothing -> ... > > > It seems strange to include a shadowed variable `x` as in your expected > code. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [elm-discuss] Re: Pattern matching using existing bound variables
On Sun, Dec 4, 2016 at 6:53 PM, David Andrews wrote: > I expect that you are actually looking to do something like this: > let > x = 1 > in > case something of > Just x -> ... > Nothing -> ... > David, are you sure you didn't mean the following? case something of Just 1 -> ... Nothing -> ... It seems strange to include a shadowed variable `x` as in your expected code. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[elm-discuss] Re: Pattern matching using existing bound variables
I think the problem is slightly different than you think. The reason the compiler complains about the redundant pattern is that "x" already matches everything. There are no more cases for "_" to handle. This compiles with no problem: let x = 1 in case something of x -> ... I expect that you are actually looking to do something like this: let x = 1 in case something of Just x -> ... Nothing -> ... On Sunday, December 4, 2016 at 6:05:10 AM UTC-5, Michał Podwórny wrote: > > Thanks for clearing things out! > > W dniu niedziela, 4 grudnia 2016 02:40:41 UTC+1 użytkownik Michał Podwórny > napisał: >> >> Hi, >> >> Consider this: >> let >> x = 1 >> in >> case something of >> x -> (...) >> _ -> (...) >> >> The compiler will complain that "The following pattern is redundant", >> pointing to the wildcard. I assume that Elm ignores the fact that "x" is >> already bound, re-binds it in the first case match and that indeed makes >> the wildcard redundant. I know how I would do this in Elixir: I'd put "^" >> before "x" to explicitly say not to re-bind the x variable. Is there >> something like this in Elm? >> > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[elm-discuss] Re: Pattern matching using existing bound variables
Thanks for clearing things out! W dniu niedziela, 4 grudnia 2016 02:40:41 UTC+1 użytkownik Michał Podwórny napisał: > > Hi, > > Consider this: > let > x = 1 > in > case something of > x -> (...) > _ -> (...) > > The compiler will complain that "The following pattern is redundant", > pointing to the wildcard. I assume that Elm ignores the fact that "x" is > already bound, re-binds it in the first case match and that indeed makes > the wildcard redundant. I know how I would do this in Elixir: I'd put "^" > before "x" to explicitly say not to re-bind the x variable. Is there > something like this in Elm? > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.