News for hackers. Stuff that matters.
Re:Small Assets without the Headache in Elm 0.19 by doctor_stopsign on Tuesday August 21, 2018 @09:26AM (#17809306)
Congrats on the release! I have very high hopes for Elm in the future, and I think it truly shifts the paradigm of frontend development.

On an attempt to use Elm in production I ended up switching back to Javascript. The biggest issue I faced was lack of type-classes, which made certain parts of the code feel like I was pulling teeth to get Elm's type system to be happy. Perhaps this is more of an issue of expecting Elm to be more like Haskell than it is.

I hope Elm is able to get more adoption, and with it more examples of idiomatic approaches to problems in Elm's style. However this somewhat feels like a chicken-and-egg problem.

Regardless, this release looks great for people using it in production already!

Re:Small Assets without the Headache in Elm 0.19 by rtfeldman on Tuesday August 21, 2018 @09:36AM (#17809381)
> this is more of an issue of expecting Elm to be more like Haskell than it is.

Yep, that's it right there.

I wonder if there's some way we could make it clearer that Elm is not Haskell, and trying to use it like it's Haskell won't likely to lead to a good experience.

At any rate, thank you for the feedback! It's definitely an ongoing communication challenge since the two languages have so much syntax in common.

Re:Small Assets without the Headache in Elm 0.19 by baublet on Tuesday August 21, 2018 @09:41AM (#17809432)
Concur. Elm is an excellent addition to one's development quiver. Its strictness made me a far better, more careful programmer, and the push toward functional, side-effect free programming styles (something also coming from the React community) has been a huge boon to the JS world. Loving the current state of JS!
Re:Small Assets without the Headache in Elm 0.19 by pdamoc on Tuesday August 21, 2018 @09:37AM (#17809391)
> Perhaps this is more of an issue of expecting Elm to be more like Haskell than it is.

Some people have a hard time in Elm because they expect Elm to behave like a language that they are already familiar with. The most frequent impedance mismatch issues I've seen are reaching for `type-classes` or attempting to implement various polymorphic behaviors and people who are too hungover on imperative constructs (Elm is declarative).

Once people start using Elm the way it was designed to be used, things become simple and start to flow.

Re:Small Assets without the Headache in Elm 0.19 by undreren on Tuesday August 21, 2018 @09:42AM (#17809445)
> Once people start using Elm the way it was designed to be used, things become simple and start to flow.

But how will anyone ever get anything done, when they can't make everything in their code exceptionally clear by wrapping it all up in a 15 monad thick monad-combinator? /s

But yes, I totally agree. Elm is a simpler, safer and easier Haskell for the front-end. I just love it :)

Re:Small Assets without the Headache in Elm 0.19 by comex on Tuesday August 21, 2018 @11:57AM (#17810742)
The idea that wanting to use typeclasses in Elm is an impedance mismatch would be more convincing if Elm and its standard library truly did everything without them, using alternate approaches like explicit dictionary passing. But as you probably know, they don’t. Instead, the language has special syntax for three builtin “typeclasses”: comparable, appendable, and number. And the standard library uses them: its Dict, for example, requires the key type to be comparable. These classes are automatically implemented for various builtin types, but there’s no way to implement them for custom types, so you can’t have Dicts with custom types as keys (unless that changed very recently). And if you want to, say, implement a hash map data structure, which requires the keys to be hashable, you have to use a completely different design, since “hashable” is not one of the three magic typeclasses.

To me, rather than principled, that just feels incomplete.

Re:Small Assets without the Headache in Elm 0.19 by rtfeldman on Tuesday August 21, 2018 @12:45PM (#17811226)
Elm handles those things the way Standard ML does, not the way Haskell does.

It's cool if you prefer the way Haskell does it, though! You should check out PureScript, which chose to do it the way Haskell did it.

Re:Small Assets without the Headache in Elm 0.19 by comex on Tuesday August 21, 2018 @02:36PM (#17812440)
> Elm handles those things the way Standard ML does, not the way Haskell does.

That's the thing, though: it doesn't. Sure, Elm is expressive enough to allow use of dictionary passing as a substitute for typeclasses, and as you noted, this approach has some resemblance to how ML modules work – albeit with less sugar. However, Elm's standard library does not seem to think this is the best approach, since it instead uses the aforementioned special-cased typeclasses.

Re:Small Assets without the Headache in Elm 0.19 by rtfeldman on Tuesday August 21, 2018 @02:53PM (#17812608)
> use of dictionary passing as a substitute for typeclasses

No, I mean that neither Elm nor Standard ML has nor needs typeclasses. No language needs typeclasses.

Both Elm and Standard ML have additional type constraints for numbers and comparable types that aren't implemented in terms of a user-definable type constraint like Haskell's typeclasses.

Another example of their being different is that Haskell offers custom user-defined operators, whereas Elm intentionally does not allow user-defined operators. There are a fixed list of them, and that's it. A great many languages have that policy too, and I would not call them wrong to do it that way.

Again, there are sound design reasons to make either choice! There are costs and benefits to making things user-definable. If you prefer the way Haskell did it, great! That's why we have different programming languages. :)

Re:Small Assets without the Headache in Elm 0.19 by bjz_ on Tuesday August 21, 2018 @07:27PM (#17814811)
> No, I mean that neither Elm nor Standard ML has nor needs typeclasses. No language needs typeclasses.

Standard ML has less need for type classes because it has a much more expressive module system, but it still can be extremely tedious to pass around module definitions all the time, which is why they added equality types when the language was originally designed. This is considered an ugly hack though, even by its own creators [0].

Definitely agree that folks should aim for better than type classes, especially due to complications around global instance coherence. One nice solution is modular implicits/instance arguments [1][2]. Tricky thing is to do it without adding too much complexity to the language.

I do wish that there would just be some acknowledgment that it's a hard, but real problem to solve for Elm's point in the design space, rather than just pretending it isn't there. It's ok just to say that you're not spending design capital on it at the moment due to more pressing issues!

[0]: https://github.com/SMLFamily/Successor-ML/issues/18

[1]: https://arxiv.org/abs/1512.01895

[2]: https://www.researchgate.net/profile/Dominique_Devriese/publ...

Re:Small Assets without the Headache in Elm 0.19 by Athas on Tuesday August 21, 2018 @03:31PM (#17812913)
> Both Elm and Standard ML have additional type constraints for numbers and comparable types that aren't implemented in terms of a user-definable type constraint like Haskell's typeclasses.

That's not really true. Standard ML has overloaded operators for int/real, but you cannot write a polymorphic function over any kind of number without using the module system. This is a key distinction. Standard ML does have a notion of 'equivalence type variables', which is frequently seen as a wart (since you often get an equality definition you might not be interested in). Standard ML has nothing for 'comparable' types (except, again, through the module system).

Offhand, I can't really think of any other language that uses builtin type classes in the style of Elm.

Re:Small Assets without the Headache in Elm 0.19 by Skinney on Tuesday August 21, 2018 @04:14PM (#17813331)
I guess Go is the only language which comes close, which has map and array/slice which cannot be implemented in the language itself. Though it's the lack of generics, not ad-hoc polymorphism which is Go's lack.

Then again, it wouldn't surprise me if of all the languages you've thought about, Elm is the only one which hasn't reached 1.0 yet.

I think Elm will get some mechanism of ad-hoc polymorphism before it reaches 1.0, but I don't think it will be type classes. Though, I have been wrong before.

Re:Small Assets without the Headache in Elm 0.19 by sridca on Tuesday August 21, 2018 @01:29PM (#17811757)
I agree with you.

Elm is not going to change, however fortunately there are alternatives. Pick something like PureScript or GHCJS and move on like I did.

I now write Haskell professionally[1] both for frontend and backend, something that you'd be hard-pressed to achieve with the likes of Elm.

[1] https://www.youtube.com/watch?v=riJuXDIUMA0

Re:Small Assets without the Headache in Elm 0.19 by leshow on Tuesday August 21, 2018 @03:16PM (#17812802)
I don't think it's crazy to wish for some kind of interface or trait-like abstraction mechanism in a language. Anything taken to the extreme can sound stupid.

edit: I'm not saying Elm should change, the time for that is long gone. Just that the idea someone would want an interface (to do things like bound on generically) isn't that far fetched.

Re:Small Assets without the Headache in Elm 0.19 by Skinney on Tuesday August 21, 2018 @04:15PM (#17813351)
> the time for that is long gone

What makes you say that? Elm has yet to reach 1.0, anything can happen. It's not likely it will happen any time soon, however.

Re:Small Assets without the Headache in Elm 0.19 by leshow on Thursday August 23, 2018 @09:24AM (#17827023)
> What makes you say that?

Because Evan has shown no interest in implementing a feature like what I'm describing.

Re:Small Assets without the Headache in Elm 0.19 by Skinney on Sunday August 26, 2018 @06:43AM (#17845274)
That's like saying Go will never get generics because it doesn't have it right now. Evan doesn't believe type classes are a right fit for Elm, but he has never to my knowledge ruled out that ad-hoc polymorphism will be added to the language.
Re:Small Assets without the Headache in Elm 0.19 by masklinn on Tuesday August 21, 2018 @10:46AM (#17810048)
FWIW you may be interested in Purescript, it's less developed than Elm but is more on-board with abstractions & the like.
Re:Small Assets without the Headache in Elm 0.19 by rtfeldman on Tuesday August 21, 2018 @01:27PM (#17811735)
It's more accurate to say PureScript has Haskell-like (or category-theoretic, if you prefer) abstractions.

All high-level programming languages are on board with abstractions, pretty much by definition!

Re:Small Assets without the Headache in Elm 0.19 by masklinn on Wednesday August 22, 2018 @03:45AM (#17817058)
> All high-level programming languages are on board with abstractions, pretty much by definition!

They all provide abstractions, but they're not necessarily on board with letting users build new abstractions. Go is famously absolutely not on board with it for instance. Elm significantly less so — and I think the more restricted use-case also makes the issue significantly less problematic, at least it was in my (admittedly limited) experience — but it's still way downslope from the likes of Haskell or OCaml.