workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
elmlang
general
In Java class designers are encouraged to provide `equals` and `hashCode` methods if they intend to use objects as Map keys
2019-01-30T04:34:49.348700
Lynne
elmlang
general
It must have been done for a reason given the language's history
2019-01-30T04:35:15.349100
Lynne
elmlang
general
That requires information to be present at runtime which isn't present at runtime, such as the names of the constructors. With `--optimize`, those are stripped so you can have smaller artifacts. Additionally, the compiler does unboxing in `--optimize` mode, meaning something aren't even in a "box" anymore. I.e. `type Foo = Foo String` will result in plain, bare strings being used, rather than objects that contain a string.
2019-01-30T04:37:12.349700
Huong
elmlang
general
<@Lynne> hmm, in other languages, Enums are often stored as Ints. perhaps something similar could be used for custom types?
2019-01-30T04:37:20.349900
Nana
elmlang
general
That is what Elm compiles them to when you don’t add values to them. If they carry values however, they become objects to allow for this. :slightly_smiling_face:
2019-01-30T04:38:14.351100
Timika
elmlang
general
Debug.toString was just an example, it wouldn't have to be the actual name, just some kind of unique thing
2019-01-30T04:39:45.352700
Nana
elmlang
general
So that would only work for _enum-like_ custom types. I can vaguely remember a discussion about this.
2019-01-30T04:39:56.353100
Timika
elmlang
general
Yeah, since we are talking only about custom types converting to ints might be a way to go if only they did not have arguments :slightly_smiling_face:
2019-01-30T04:39:57.353200
Lynne
elmlang
general
but if I had: ``` type Foo = Foo type Bar a = Bar a ``` then `Bar Foo` could still probably be converted into a more clever thing than an object, maybe some mathematical operation combining the Int representations of `Foo` and `Bar` ?
2019-01-30T04:42:15.355100
Nana
elmlang
general
probably way faster than big String comparisons, though could still get slow on large structures
2019-01-30T04:43:31.356800
Nana
elmlang
general
I was referring to smth like `type Foo = Bar Int | Baz String | Quu Gender`, where the solution is not obvious, at least to me.
2019-01-30T04:43:34.356900
Timika
elmlang
general
And in case of `Bar SomeLongRecord`?
2019-01-30T04:43:41.357100
Lynne
elmlang
general
<@Lynne> yeah it could still get slow
2019-01-30T04:44:14.357800
Nana
elmlang
general
Not even slow, how would you assign a number in this case?
2019-01-30T04:44:33.358500
Lynne
elmlang
general
It is pretty simple when using enum-like types or types which only take enum-like types, but then such a restriction should appear in the language
2019-01-30T04:45:11.359800
Lynne
elmlang
general
I think this is one of the problems that look easy to solve until you dive a bit deeper, then they become super hard, especially when you factor in elegance of design and ergonomics.
2019-01-30T04:45:33.360400
Timika
elmlang
general
So pretty much extend `comparable` to enum-like types and we are good to go
2019-01-30T04:45:39.360600
Lynne
elmlang
general
Still won't be super useful though :slightly_smiling_face:
2019-01-30T04:45:58.361100
Lynne
elmlang
general
<@Lynne> though it'd probably be bad to have this feature for enum-likes only. That'd make other custom types a bit of a second-class citizen, which would encourage worse code
2019-01-30T04:48:41.362300
Nana
elmlang
general
so yeah :pensive:
2019-01-30T04:49:11.362700
Nana
elmlang
general
That's why I said it won't be super useful
2019-01-30T04:49:16.362900
Lynne
elmlang
general
I use `Uuid` and would be happy having them as dict keys
2019-01-30T04:49:34.363300
Lynne
elmlang
general
But `Uuid` is not an enum-like type
2019-01-30T04:49:52.363700
Lynne
elmlang
general
And, generally speaking, it is not possible to come with an integer number for it, only some float (probably with double precision)
2019-01-30T04:50:51.364600
Lynne
elmlang
general
(I mean an integer which would fit into `Int` type)
2019-01-30T04:51:44.365000
Lynne
elmlang
general
<@Lynne> hmm, so for you, `AssocList` could actually be faster than `Dict String Stuff` ? :thinking_face:
2019-01-30T04:55:22.366400
Nana
elmlang
general
because `==` doesn't do a full string comparison to check wether too Uuids are equal, right?
2019-01-30T04:56:11.367100
Nana
elmlang
general
How do you mean it does not do full string comparison?
2019-01-30T04:59:03.367600
Lynne
elmlang
general
or maybe it does? don't know how it works
2019-01-30T04:59:41.368500
Nana
elmlang
general
If custom types are represented as JS objects then Kernel will do structural comparison, i.e. it will compare strings
2019-01-30T04:59:42.368600
Lynne
elmlang
general
But I don't know how they are represented in 0.19. In 0.18 they were objects if I remember correctly
2019-01-30T05:00:28.369300
Lynne
elmlang
general
but with immutable datastructures, aren't you supposed to be able to check equality by just checking the top node?
2019-01-30T05:01:05.370000
Nana
elmlang
general
Could you elaborate on this?
2019-01-30T05:01:25.370200
Lynne
elmlang
general
<@Nana> yes, you can do reference comparisons, but that's only helpful if these data structures are related in some way
2019-01-30T05:02:18.371200
Earlean
elmlang
general
They still are in cases where you have a value with them. Otherwise `--optimize` will make them numbers.
2019-01-30T05:02:23.371300
Timika
elmlang
general
eg. if one is a slightly modified version of the other
2019-01-30T05:02:43.371700
Earlean
elmlang
general
Thanks, good to know :+1:
2019-01-30T05:02:49.371800
Lynne
elmlang
general
Not sure I understood you <@Earlean>
2019-01-30T05:04:38.374300
Lynne
elmlang
general
If you have `a = [1, 2]` and `b = [1, 2]`, they will be two different references but equal in value.
2019-01-30T05:04:53.374600
Bert
elmlang
general
That's why there is structural comparison, right?
2019-01-30T05:05:25.375000
Lynne
elmlang
general
`Basics.eq` is actually doing reference comparison as first step (pretty logical) before it dives deeper in the structure
2019-01-30T05:05:42.375600
Lynne
elmlang
general
<@Lynne> I just remember Immutable.js presenting this as an advantage
2019-01-30T05:05:56.376200
Nana
elmlang
general
I mean JS function which `Basics.eq` is backed by
2019-01-30T05:05:57.376500
Lynne
elmlang
general
<@Bert> yeah that makes sense, so I guess you can quickly prove a positive, but not a negative
2019-01-30T05:06:19.377400
Nana
elmlang
general
<@Nana> It is very possible I am just not sure I understood what "top node" is
2019-01-30T05:06:29.377600
Lynne
elmlang
general
Right. Think of an immutable linked list.
2019-01-30T05:06:59.378100
Bert
elmlang
general
Prepend an item and you have a longer linked list, but the "top node" is now different
2019-01-30T05:07:56.379100
Bert
elmlang
general
If it is a graph node, then, yes, in case of immutable data structures simple reference comparison of the node says if you need to dive deeper to the children
2019-01-30T05:08:26.379900
Lynne
elmlang
general
right, so I guess when you use `==` on two `Uuid`s, would it first check reference equality, but if that returns false, it'd to a full structural comparison? so when going through a list to find a match, you wouldn't get any benefit from it
2019-01-30T05:12:15.381700
Nana
elmlang
general
That's exactly what `Basics.eq` is doing
2019-01-30T05:12:38.382100
Lynne
elmlang
general
<https://github.com/elm/core/blob/22b2d7a235003a88af4e4af58c3d0edf43684bc9/src/Elm/Kernel/Utils.js#L35>
2019-01-30T05:13:14.382400
Lynne
elmlang
general
thanks, this was an interesting discussion :slightly_smiling_face:
2019-01-30T05:17:25.383100
Nana
elmlang
general
hello everyone! is it possible to pattern match on a string in elm? say I have a string that has a well defined structure and would like to extract the separate info from it?
2019-01-30T05:57:37.384400
Karrie
elmlang
general
<@Karrie> ah, not like that, you'll have to parse it into a record or something first
2019-01-30T05:59:12.385400
Nana
elmlang
general
or just use Regex, that might be the simplest
2019-01-30T06:01:16.385700
Nana
elmlang
general
(by pattern match I assume you meant `case .. of`)
2019-01-30T06:02:07.386100
Nana
elmlang
general
Sadly, pattern matching in Elm is not as powerful as in Elixir yet
2019-01-30T06:04:24.386600
Lynne
elmlang
general
<@Nana> in elixir you can do `def my_func("say:" &lt;&gt; &lt;&lt;digit::bytes-size(1)&gt;&gt; &lt;&gt; ":" &lt;&gt; thing) do ... end`
2019-01-30T06:17:02.388200
Karrie
elmlang
general
but I guess it’s not possible in elm yet thanks <@Lynne> and <@Nana>!
2019-01-30T06:17:30.388800
Karrie
elmlang
general
<@Karrie> You could write a parser using <https://package.elm-lang.org/packages/elm/parser/latest/> and pattern match on the result of `Parser.run`
2019-01-30T06:21:57.389600
Jin
elmlang
general
<@Jin> amazing! how did I know about this already?! thank you very much!!
2019-01-30T06:22:51.390600
Karrie
elmlang
general
is there a way to trigger the `scrollIntoView()`-method of a DOM element rendered by Elm _without_ using ports (because ports need a full update -&gt; view circle with a model and stuff but I want to trigger the `scrollIntoView()` on a simple view-component without state)?
2019-01-30T07:37:06.393100
Daysi
elmlang
general
help would be greatly appreciated
2019-01-30T07:40:28.393600
Daysi
elmlang
general
That's not how Elm works, so not possible
2019-01-30T07:41:00.393900
Lynne
elmlang
general
wow
2019-01-30T07:41:19.394100
Daysi
elmlang
general
hmm I think you can use `Browser.Dom.setViewPort` ?
2019-01-30T07:42:12.396000
Nana
elmlang
general
You don't need model and stuff (can simply use `()` as your model) but you have to send some command to trigger side effects
2019-01-30T07:42:18.396200
Lynne
elmlang
general
<@Nana>, it is a `Task`, still not possible with just a view
2019-01-30T07:43:11.397100
Lynne
elmlang
general
yeah not just with view, that'd be weird anyway :stuck_out_tongue:
2019-01-30T07:43:50.398100
Nana
elmlang
general
the problem is I want to have a reusable state-less component, which handles the "onClick" independently from the client-code which uses it. Could I implement a "private" update-function on this component?
2019-01-30T07:44:32.398500
Daysi
elmlang
general
e.g. look at the scrollable TabBar example from material design here <https://material-components.github.io/material-components-web-catalog/#/component/tabs>
2019-01-30T07:45:06.399000
Daysi
elmlang
general
I am implementing this right now and need the tabs to `scrollIntoView()` on click
2019-01-30T07:45:29.399800
Daysi
elmlang
general
but I don't want to delegate this to the client-code every time
2019-01-30T07:45:45.400500
Daysi
elmlang
general
<@Daysi> yes, your view component can take a "message handler" as an argument, which lets you do stuff like that
2019-01-30T07:46:33.401400
Nana
elmlang
general
how so?
2019-01-30T07:47:05.402000
Daysi
elmlang
general
Shortly, there is no "private" update functions
2019-01-30T07:47:12.402200
Lynne
elmlang
general
<@Lynne> no _exposed_ update function. You get what I mean... no?
2019-01-30T07:47:56.403500
Daysi
elmlang
general
All messages you send from your "subcomponents" (in Elm world there is a long-running discussion if "component" is an appropriate term at all) have to go via top-level program (client code in your terms if I got you right)
2019-01-30T07:48:24.404100
Lynne
elmlang
general
<@Daysi> I think I get, but, again, that's not how Elm works :slightly_smiling_face:
2019-01-30T07:48:58.404900
Lynne
elmlang
general
but it wouldn't make sense for the top-level program to handle stuff which belongs into the responsibilities of the view layer
2019-01-30T07:49:17.405400
Daysi
elmlang
general
Who would be triggering this private function if it was there?
2019-01-30T07:49:25.405800
Lynne
elmlang
general
the user
2019-01-30T07:49:37.406100
Daysi
elmlang
general
Programmaticaly
2019-01-30T07:49:48.406500
Lynne
elmlang
general
Given the Elm runtime and stuff
2019-01-30T07:49:54.406800
Lynne
elmlang
general
Well, the only thing top-level program needs to do in this case is to delegate certain messages to another module's `update` function
2019-01-30T07:50:19.407800
Lynne
elmlang
general
So you still have separation of concerns, it is just the message flow which always starts from top
2019-01-30T07:50:53.408600
Lynne
elmlang
general
but the top-level program shouldn't be aware that there are any messages which don't concern it, i.e. `scrollIntoView()`
2019-01-30T07:51:39.409400
Daysi
elmlang
general
it should only care about business-related logic, not view-related logic
2019-01-30T07:52:40.410800
Daysi
elmlang
general
Well, it does not have be aware of exact messages (is it `scrollIntoView` or `scrollOutOfView` should not concern it), but it has to be aware of the very presence of messages themselves
2019-01-30T07:52:51.411100
Lynne
elmlang
general
I hear OO in what you are saying :slightly_smiling_face:
2019-01-30T07:53:12.411400
Lynne
elmlang
general
<@Daysi> here's the most basic version of such a "component" <https://ellie-app.com/4BfGmGPKKdva1>
2019-01-30T07:56:30.412500
Nana
elmlang
general
in the example it only returns it's new state, however it could also return other things like `(model, Cmd.msg)` which is how you can use Tasks like setting the viewport
2019-01-30T07:58:26.414200
Nana
elmlang
general
<@Lynne> *triggered*
2019-01-30T08:00:47.414500
Daysi
elmlang
general
:smile:
2019-01-30T08:00:48.414700
Daysi
elmlang
general
no seriously, I don't know why you hear OO
2019-01-30T08:01:19.415400
Daysi
elmlang
general
abstraction and encapsultion of reponsibility is a universal concept not related to OO or FP
2019-01-30T08:02:01.416800
Daysi
elmlang
general
<@Nana> thanks
2019-01-30T08:02:16.417500
Daysi
elmlang
general
"business-related logic", "view-related logic" are terms I've never heard since I started working with Elm
2019-01-30T08:02:41.418300
Lynne
elmlang
general
People just tend to call things differently here
2019-01-30T08:02:50.418800
Lynne
elmlang
general
with this type of "mapping" you can do encapsulation in Elm, and it lets you create "components" that can have private state and do effects. it's just that they always have to "go through the parent"
2019-01-30T08:03:50.420700
Nana