Also used by Rust. +1
--
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.
> They're called enum because you can enumerate all values.
I don't follow your argument, you seem to be saying that "enumerate" is not a good word for describing the act of defining a closed, finite set of constructors?
Said differently: Who ever said it's about enumerating values; it's just a quirk of Java that enums are all arity zero.
Since I've been doing a lot of rust recently, this was a good explanation:
http://doc.rust-lang.org/tutorial.html#data-structures
I see Ray's point about the need for stability but I don't want Elm to get too tied down yet. As has been mentioned, Swift and Rust's concepts of enums have parameters, and it's strictly more powerful that not having parameters. ("They're not real enums" indeed.) No one is criticizing their case statements for not having automatic fall-through; the point being that we shouldn't bind ourselves to languages patterns from the 70s, whether C or ML. (C actually has two "sum types", enums and unions, and I would argue that they should be combined as we are doing.) So yes, I support this change.At the risk of pointing out what you already know, ADTs/enums share a reciprocal relationship. Sum types can be created using one of many types, but consumers must be ready to handle one of any type. "Product types" (Elm records, C structs) require terms of all types at creation, but consumers have their choice of type to extract.
--
In many (most) languages an Enum type entails some kind of ordinality. ... To me (and I know this is not true in every language) it ain't an enum without an associated ordinal relation on the type values.
I think enum is okay. Enums have always been associated with switch statements and extending them to full pattern matching seems natural.
So Laszlo shared this idea with me today: what if data was renamed to enum? And what if instead of saying algebraic data types we said enums?enum Maybe a = Just a | NothingThe idea is that it's type where you can enumerate all the possible values. If you didn't enumerate it, you can't use it. I think this captures the fact that ADTs are "closed" in a really concise way.This also builds off people's existing knowledge of enums. It lets us say, "Elm does enums right" or "it's like Java enums but way more useful." Immediately people know what it is and see that it's an improvement over what they are using.This terminology is also used by Haxe and Swift. I'd like to look into both a bit more. It looks like Swift does some weird / possibly useful stuff.What do you think of this? Since 0.13 has slipped a couple weeks I was thinking this should be in there.Notes on context and motivation:
We just had a thread about how to nicely represent many different things with the same type. Coming from an OO language, the intuitive thing is to use records. They seem like objects and they say they are extensible, but they don't fill the same role exactly. The name "algebraic data type" in no way indicates that it is going to solve this problem.Along with this other thread where I got concerned about alienating and bizarre names, I started thinking about what we could call ADTs instead. Weirdly, Laszlo brought it up right after that :)As I thought through this idea, I also realized that I could not explain why it is called an algebraic data type. What is the algebraic part? Wikipedia did not have the answer, nor do I remember it from any university class or book or anything. I just accepted that that was the name of it.
> That is, why is a keyword necessary to say that Pos = ... is a type definition? The lexical structure should be enough to determine that.
I think that this is worth exploring. We probably get it for free because type identifiers are capitalized.
type Point = { x:Float, y:Float } ?type Point = { x:Float, y:Float } deriving JSONtype Point = ... deriving JSON will really introduce a new type, not just an alias. Since then the JSON functionality wouldn't apply to any old q : { x:Float, y:Float }, only to q : Point.About alias generally, I had not thought about record types in that context. It is true that having a record system, one will probably use the keyword often in circumstances one would simply not have in Haskell, and in which (in Elm) the connotation of alias is not perfect. What do you mean by "record constructors"? Do you mean the type "constructor" Point intype Point = { x:Float, y:Float }?
Maybe a special record keyword would indeed be better. Is there a clear syntactic or semantic distinction between a) current uses of type that would more appropriately be uses of record, and b) current uses of type that wouldn't meaningfully be uses of record, because they are really just aliasing of existing types?
About possible interactions with type-directed macros/deriving, good question. Here's a thing to consider: If you write
type Point = { x:Float, y:Float } deriving JSON
do you expect the JSON functionality to only be made available for values explicitly types as p : Point, or also for values q that just happen to be exactly records with exactly x and y fields of type Float (but with no nominal typing as Point)? If the latter, is this really going to work in the compiler?
If the former, thentype Point = ... deriving JSONwill really introduce a new type, not just an alias. Since then the JSON functionality wouldn't apply to any old q :{ x:Float, y:Float }, only to q : Point.
I suspect the Haskell type theorists will not like group one bit. As for tagged, I might suggest tag, but that seems like a useful identifier to have free.To the point that "enum means nothing to non-programmers": To what extent are we trying to attract non-programmers, and to what extent are we attracting programmers from other languages? I would say it's primarily, but not exclusively, the latter. Also, data doesn't just mean nothing, it means the wrong thing. enum might have little meaning to non-programmers, but it's used in the same way as other modern languages (Swift, Ruse) and as a logical extension on C-style languages. If "enums are ADTs" is the new, emerging consensus, we do ourselves a disservice by picking out a new name like tagged. Name intuitions are a double-edged sword: ideally you can pick a name that builds on the user's intuition, but it's better to pick out a meaningless name than fight existing ideas.
--
I suspect the Haskell type theorists will not like group one bit. As for tagged, I might suggest tag, but that seems like a useful identifier to have free.To the point that "enum means nothing to non-programmers": To what extent are we trying to attract non-programmers, and to what extent are we attracting programmers from other languages? I would say it's primarily, but not exclusively, the latter. Also, data doesn't just mean nothing, it means the wrong thing. enum might have little meaning to non-programmers, but it's used in the same way as other modern languages (Swift, Ruse) and as a logical extension on C-style languages. If "enums are ADTs" is the new, emerging consensus, we do ourselves a disservice by picking out a new name like tagged. Name intuitions are a double-edged sword: ideally you can pick a name that builds on the user's intuition, but it's better to pick out a meaningless name than fight existing ideas.
--
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/UaYVp2-Xleo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
Yeah, we're still messing with the language. If you can't handle that, either don't upgrade or don't use Elm. We're very far away from 1.0.
--
My concern with data -> type, type -> alias is that maybe you want to introduce types in some other way, with a language feature not yet thought of. I dislike alias because it's not clear it's only for types, not terms.You can have an enum with a single term in it in C. In fact, I've seen this used in APIs that will grow beyond that one option in the future. (SemVar vs. YAGNI, go!)model is an interesting suggestion, but I feel that it's going to confuse the hell out of MVC people. I feel like it's the programmer's just to provide semantic abstractions and it's the language's job to provide many tools to do that. I decide what a model is, not the language; that's a high-level concept. model also doesn't seem ADT specific; should I be able to do model Point with {x : Float, y: Float} as well? If we do go this route, I suggest swapping with for as, which is already a reserved word, assuming it can be parsed unambiguously (I think it can).I really like the ScreenPos and GamePos position. I was going to ask for some sugar for them, thinking you'd need to have a case statement, but if you're clever it's not so bad. Share-elm is down, so at the risk of a further tangent, this is as neat as I can get them:type Position = {x:Float, y:Float}data GamePos = GamePos Position
f : GamePos -> Stringf (GamePos {x,y}) = show x ++ " " ++ show y
main = asText . f . GamePos <| Position 4 5
--
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.
Could we maybe make some words keywords only if they are in the leftmost column? Or would that be more confusing?
Maybe 'type' keyword should have a second part 'type _' in ('model', 'alias'...)
--
type Special : String -- I'm an aliastype Foo = String -- I'm an ADTtype Maybe a = Just a | Nothing -- me tootype Point : {x: Int, y:Int} -- I'm the type of a record.
module X whereimportJsonJavascript.Experimental as JSEDict (empty,insert)
type
Maybe a = Just a | Nothing
Point = {x: Int, y: Int}
func : String -> Stringfunc x = . . .
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/UaYVp2-Xleo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
On Sep 3, 2014 8:22 AM, "Alexander Noriega" <lambd...@gmail.com> wrote:
>
> My 2 cents:
>
> Not convinced at all by the arguments in favor of `enum`. But I don't have a suggestion, because I don't know of a better word than `data` for defining shapes of data.
>
> I introduce Elm to JS/HTML/CSS/PHP devs all the time. `data`: simple to explain. `enum`: totally alien, plus makes it sound like it's going to be a complicated thing.
Is there some way we could test this rather than speculating?
>
> IDK why the focus is the "problems" with the `data` keyword anyway. For me, `type` being used for aliases is by far the main offender here. It is certainly the one generating the questions when I introduce Elm to anyone.
For people who have used C before, changing "type" to "typedef" would make it more familiar. I doubt it would help people without that experience though.
Another thing to consider is that someone learning Elm first might then go on to learn other languages like Swift or C someday. So using these terms would make them more familiar when moving in the other direction.
--
How about "datatype"?
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/UaYVp2-Xleo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.