Re: [elm-discuss] Would Enums make a good addition to Elm?

2017-08-03 Thread Mark Hamburg
I thought about whether this was an opportunity to improve error messages
but wasn't sure what the improvement would be. Is it detection that a
previous case already matched everything? Is it specifically noting that
the case involved a variable that shadows an existing variable? Or is this
something better covered with a warning rather than an error about variable
shadowing? For example:

Warning: The pattern variable "foo" shadows the definition at line 342.
Patterns can only use constructors and explicit string and numeric
constants. If you need to compare against a variable, use an if expression.
If you intended to use a pattern variable, you can eliminate this warning
by choosing a different name.

Mark

On Wed, Aug 2, 2017 at 4:27 PM Richard Feldman 
wrote:

> Mark - this seems like a great addition to the error message catalog
> ! I've heard of people
> encountering this too.
>
> Seems like it should be easy enough to detect, and the compiler could
> either provide a concise explanation of what's going on or link to a longer
> explanation.
>
> --
> 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] Would Enums make a good addition to Elm?

2017-08-02 Thread Richard Feldman
Mark - this seems like a great addition to the error message catalog 
! I've heard of people 
encountering this too.

Seems like it should be easy enough to detect, and the compiler could 
either provide a concise explanation of what's going on or link to a longer 
explanation.

-- 
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] Would Enums make a good addition to Elm?

2017-08-02 Thread Mark Hamburg
Something like this would probably address a "puzzle" I just resolved
yesterday for one of the engineers on my team. He was testing character
codes and did what one would be inclined to do in most programming
languages and defined names for referencing the values — e.g., leftArrowKey
: Int. He then tried to case on them and was puzzled at why the following
code complained about a redundant pattern:

case keyCode of
leftArrowKey -> ...
rightArrowKey -> ...
_ -> ...


Of course, what's happening here is that the mentions of leftArrowKey and
rightArrowKey in the case statement are each creating new pattern variables
that have nothing to do with the definitions elsewhere of those names. So,
Elm's error message is correct but in this case not helpful. More to the
point, however, the fixes were to either just use the constant values
directly or to replace the case expression with a sequence of if
expressions. Neither of those are particularly attractive. The conclusion
of our exchange was that it would be nice to have some form of named
constants that could be used in case expressions, but adding them would run
counter to Elm's minimalist inclinations.

Mark

On Wed, Aug 2, 2017 at 7:00 AM, Robin Heggelund Hansen  wrote:

> I think most people find that Union Types are a wonderfull thing. I would
> argue that much of the beauty of Union Types comes from using them in a
> case-of statement, having the compiler complain when there is a case one
> haven't covered.
>
> Strings and numbers are not so wonderfull, because they span essentially
> unlimited values, so case-of statements become less valuable.
>
> However, strings and numbers still need to be used in production apps for
> several reasons:
> 1) Union Types is not supported in Json, so one needs to convert to/from
> strings or numbers for communicating with other systems.
> 2) Union Types are not comparable, and so cannot be used as keys in Sets
> or Dicts.
>
> So a server might send me some json where the current user language is
> represented by an Int (0  and 1, norwegian and english) and the current
> game being played is a string ("chess", "checkers", "reversi"). It would be
> great to have some compiler help for these values (say, you forgot the case
> statement for "reversi"), AND it would be great to avoid writing
> encoders/decoders for the union types and converting back and forth several
> places.
>
> Enums would help with this.
>
> The way I imagine this to work is that an enum essentially represents a
> restricted set of String or Number. Once the compiler sees that you're
> working with an enum, it could help you out in case statements. And since
> an enum is just a string, or just a number, they can be used in the same
> places where one would normally use them, like as a value in a select.
>
> One would need a way to check that a string/number matches the values of
> an enum though. Something like `Enum.matches : MyStringEnum -> Maybe (Enum
> MyStringEnum)`.
>
> The one thing I can think of which makes this a bad addition to Elm, is
> that it might be a bit confusing for beginners when to use enum and when to
> use unions... maybe.
>
> Anyway, what do people think of this?
>
> --
> 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.


[elm-discuss] Would Enums make a good addition to Elm?

2017-08-02 Thread Robin Heggelund Hansen
I think most people find that Union Types are a wonderfull thing. I would 
argue that much of the beauty of Union Types comes from using them in a 
case-of statement, having the compiler complain when there is a case one 
haven't covered.

Strings and numbers are not so wonderfull, because they span essentially 
unlimited values, so case-of statements become less valuable.

However, strings and numbers still need to be used in production apps for 
several reasons:
1) Union Types is not supported in Json, so one needs to convert to/from 
strings or numbers for communicating with other systems.
2) Union Types are not comparable, and so cannot be used as keys in Sets or 
Dicts.

So a server might send me some json where the current user language is 
represented by an Int (0  and 1, norwegian and english) and the current 
game being played is a string ("chess", "checkers", "reversi"). It would be 
great to have some compiler help for these values (say, you forgot the case 
statement for "reversi"), AND it would be great to avoid writing 
encoders/decoders for the union types and converting back and forth several 
places.

Enums would help with this.

The way I imagine this to work is that an enum essentially represents a 
restricted set of String or Number. Once the compiler sees that you're 
working with an enum, it could help you out in case statements. And since 
an enum is just a string, or just a number, they can be used in the same 
places where one would normally use them, like as a value in a select.

One would need a way to check that a string/number matches the values of an 
enum though. Something like `Enum.matches : MyStringEnum -> Maybe (Enum 
MyStringEnum)`.

The one thing I can think of which makes this a bad addition to Elm, is 
that it might be a bit confusing for beginners when to use enum and when to 
use unions... maybe.

Anyway, what do people think of this?

-- 
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.