Nope, you can't do this. Any lower-case variables in a pattern match are
newly bound.

Part of this is because equality is not always well defined in Elm i.e. we
don't want you to be able to do this:

let
  f : Int -> Int
  f x = ...
  someMaybeVal : Maybe (Int -> Int)
  someMaybeVal = ...
in
  case someMaybeVal of
    Just f -> ...
    Nothing -> ...

If you did this, it would try to compare the function in the Maybe to f,
which it can't do. Elixr is dynamically typed, so they'll let you do things
like that willy nilly, but we don't want such a program to be allowed in
Elm.
(There's a whole bunch of other issues with function equality in Elm, which
we won't get into here).

This can make code more verbose in Elm, but if you want to compare values
(as opposed to patterns) use comparison functions like ==, and if then else
expressions.

On Sat, Dec 3, 2016 at 5:58 PM, Duane Johnson <duane.john...@gmail.com>
wrote:

> I don't know of a way. Use if...then...else?
>
> On Sat, Dec 3, 2016 at 12:08 PM, Michał Podwórny <podworn...@gmail.com>
> wrote:
>
>> 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.
>>
>
> --
> 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.

Reply via email to