workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
elmlang
general
try `elm install elm/svg`
2019-04-27T18:29:45.095000
Wenona
elmlang
general
Derp
2019-04-27T18:29:49.095200
Isaias
elmlang
general
:thumbsup:
2019-04-27T18:29:54.095400
Wenona
elmlang
general
Every example I come across for using ports via commands and subscriptions the signature for subscriptions is `Model -> Sub msg` but there's no examples of anyone actually using the model in their subscriptions... Anyone here have a use case where they've done something with the model in a subscription function?
2019-04-27T18:35:16.096900
Buffy
elmlang
general
I don’t have code-examples handy, but one example I can offer is that we add a `keydown` subscription when a modal is open, so we can close it when `escape` is pressed
2019-04-27T18:40:04.097900
Huong
elmlang
general
we could have the subscription always be there and filter in the model, too
2019-04-27T18:40:16.098600
Huong
elmlang
general
but then that’s always the case, I suppose - ignoring the message based on the state, or not subscribing to the event based on the state, it’s just a matter of how much work needs to happen
2019-04-27T18:41:05.100100
Huong
elmlang
general
I wish I followed that but maybe YAGNI till I do for now?
2019-04-27T18:50:34.101100
Buffy
elmlang
general
The other thing I'm curious about is if subscriptions can be attached if you're expecting a response of some sort from them and otherwise don't bother the run time? Not sure if that makes any sense.
2019-04-27T18:51:46.102300
Buffy
elmlang
general
Yeah, that’s basically what the `Model ->` part is for - based on your model, you can decide whether you are interested in receiving certain events, and hence, subscribe to those events
2019-04-27T18:56:43.103500
Huong
elmlang
general
An example of why you might need `model` is if you have a specific page in your app where you want to track time passing, but you don’t care about it otherwise. One solution is you could have a value in `model` that lets `subscriptions` know whether it should subscribe to `Time.every` or not. While you could just run the event all the time regardless and filter out what you don’t need in `update`, I feel `subscriptions` is a better place for it because: 1. you’re only running `update` constantly when necessary; and 2. it separates the logic of “do I care about this subscription?” from “how should I update my model and what effects need to happen?”
2019-04-27T18:57:45.103700
Naoma
elmlang
general
Now it makes a lot of sense! Thanks y'all! Now if only I wasn't using all this just to wrap aws-amplify lib's js calls... :confused: Not sure if interacting directly with the Http API's would be easier starting to feel like it would but the Cognito docs are dense. :man-shrugging:
2019-04-27T19:19:43.105600
Buffy
elmlang
general
Sorry <@Myong> :slightly_smiling_face:
2019-04-27T19:20:06.106100
Buffy
elmlang
general
Anybody encountered an issue with `elm publish`? I published new version of package yesterday but it's not visible on <http://package.elm-lang.org|package.elm-lang.org> package <https://package.elm-lang.org/packages/turboMaCk/lazy-tree-with-zipper/> tag <https://github.com/turboMaCk/lazy-tree-with-zipper/releases/tag/3.1.0> ``` ❯❯❯ elm publish Verifying turboMaCk/lazy-tree-with-zipper 3.1.0 ... ● Found README.md ● Found LICENSE ✗ Version 3.1.0 is not correct! -- ALREADY PUBLISHED ----------------------------------------------------------- Version 3.1.0 has already been published. You cannot publish it again! Try using the `bump` command: elm bump It computes the version number based on API changes, ensuring that no breaking changes end up in PATCH releases! ```
2019-04-28T06:48:52.107600
Zona
elmlang
general
<@Zona> I can see that version
2019-04-28T06:53:36.107800
Huong
elmlang
general
Caching issue?
2019-04-28T06:53:40.108000
Huong
elmlang
general
let me check
2019-04-28T06:54:03.108200
Zona
elmlang
general
righ... seems like aggressive client side caching I didin't expect that :smile:
2019-04-28T06:54:46.108800
Zona
elmlang
general
maybe it would be good idea to tweak headers to take that cache down a bit
2019-04-28T06:55:06.109300
Zona
elmlang
general
thx <@Huong>
2019-04-28T06:56:13.109600
Zona
elmlang
general
Are you aware about a Elm repl online "fully in the browser"? There is : <http://elmrepl.cuberoot.in/> but it seems each keystroke is sent to the server, which is a bit slow... <@Florencia> is your elm compiler-in-elm ready enough to support this kind of thing?
2019-04-28T09:39:49.111500
Loralee
elmlang
general
is there a way to decorate pointer events w the time at which it happened? something like Task.pair Time.now (pointer event)..though i know mpizenberg doesnt expose subscriptions.
2019-04-28T11:58:55.116000
Rozanne
elmlang
general
You could use the advanced section of the pointer events package and decode this standard field from the event <https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp>
2019-04-28T12:19:18.117500
Lashawnda
elmlang
general
<https://package.elm-lang.org/packages/mpizenberg/elm-pointer-events/latest/Html-Events-Extra-Pointer#eventDecoder>
2019-04-28T12:20:59.118000
Lashawnda
elmlang
general
Depending on the browser this value will have a decimal component, so if you want a `Posix` you’ll have to round it first
2019-04-28T12:25:31.119300
Lashawnda
elmlang
general
Note that this is a timestamp relative to when the document was loaded, not an absolute point in time
2019-04-28T13:01:33.119600
Huong
elmlang
general
Definitely not yet :)
2019-04-28T13:22:14.119900
Florencia
elmlang
general
but it's one of the planned usages
2019-04-28T13:23:10.120100
Florencia
elmlang
general
hi
2019-04-28T14:02:08.120500
Socorro
elmlang
general
Will union types be comparable some day?
2019-04-28T14:38:27.121600
Isaias
elmlang
general
I don’t think a decision has been made yet on that particular issue
2019-04-28T14:43:33.121700
Huong
elmlang
general
Is there a discussion thread somewhere <@Huong>?
2019-04-28T15:49:03.122000
Isaias
elmlang
general
There is a meta-issue that tracks a number of tickets related to more flexibility for `comparable` types, of which custom types is only a small part. As per usual, the goal is to (eventually) find a holistic design rather than solving just the immediate issue, thereby possibly excluding other options in the future (or making them harder to add) - <https://github.com/elm/compiler/issues/1008>
2019-04-28T15:56:57.122200
Huong
elmlang
general
Various designs have been proposed and discussed, like “use the definition order” - which has significant downsides, or a bespoke `data module where { type = .., compare = .., eq = .. }` syntax for making data-type modules that would allow making them comparable and allow overriding structural equality, but that also has significant downsides. I’m sure there have been others, though. The point is mostly this: - this is not an easy issue - making a decision means committing to a particular design, to the exclusion of other options - this does not have the highest priority right now, as there are workaround for most immediate issues stemming from the limited `comparable` type variable
2019-04-28T16:03:37.122400
Huong
elmlang
general
Ok thanks for the detailed response
2019-04-28T16:28:22.122700
Isaias
elmlang
general
Ontological question: Suppose you have types `A` and `B`, and `A` has an `A.fromB` constructor. Say you want to also make `B`'s from `A`'s. Do you make a `B.fromA` constructor or an `A.toB` deconstructor?
2019-04-28T16:37:09.129800
Isaias
elmlang
general
(I realize it might not be obvious what downsides there are to using definition order, so just to give an example - this means that if I write a library that exposes a datatype that happens to be implemented as a custom type, people might rely on the sorting order. Changing the order would then suddenly affect consumers of my library. That would be surprising and definitely lead to issues. Things would be even worst if my type is opaque - the user can’t even see what order things will be sorted in, but that implementation detail now leaks. There are arbitrary ways to limit the impact - only make simple enumerations `comparable` and/or require that the constructors be exposed - but that obviously complicates the design and means people will still ask for `comparable` custom types :smile: TL;DR: it means leaking implementation details, which is tricky business)
2019-04-28T16:37:22.129900
Huong
elmlang
general
I usually prefer `toFoo` functions, and always feel a little bad writing `String.fromInt` or `String.fromFloat` :smile: (this was for me also a point of confusion while learning Rust. While using `.into()` is a common pattern there, this is usually done by implementing a `From&lt;T&gt;` trait on the target type, rather than an `Into&lt;T&gt;` trait on the originating type)
2019-04-28T16:40:28.132500
Huong
elmlang
general
why do you prefer that?
2019-04-28T16:51:28.132900
Isaias
elmlang
general
Consistency, mostly. For whatever reason, it also matches my mental model better - I’m more likely to think “I want to turn X into Y” rather than “I want to create a Y from an X”
2019-04-28T16:55:08.134300
Huong
elmlang
general
Ah, the "source-path-goal" image schema :laughing:
2019-04-28T17:26:03.135200
Isaias
elmlang
general
never thought to check the other fields! thanks much. also great to know about the timestamp.
2019-04-28T19:47:58.136700
Rozanne
elmlang
general
Hi, I know how to decode JS object into Elm alias, but I'm not sure how to decode JS object into Custom type with more values. ``` json = { name: "Joe", unit: "CELSIUS } // elm type Unit = Celsius | Fahrenheit type alias Name = String type Setting = TemperatureSetting Name Unit ``` I would like to decode that json into `TemperatureSetting`. Could someone give me a hint? Thanks
2019-04-29T02:30:17.140600
Bethel
elmlang
general
<@Bethel> first you need to write a `String -&gt; Maybe Unit` function
2019-04-29T02:34:58.141400
Earlean
elmlang
general
that one I got.
2019-04-29T02:35:40.141900
Bethel
elmlang
general
I'm just not sure how to replace with ``` Json.map2 SettingAlias (field "name" string) (field "unit" decodeTemperature) ```
2019-04-29T02:36:25.142900
Bethel
elmlang
general
the `SettingAlias` is not alias anymore but just custom type named `Setting`
2019-04-29T02:36:48.143400
Bethel
elmlang
general
`TemperatureSetting` is a constructor for the type `Setting`, it takes a String and a Unit and gives you a `Setting`
2019-04-29T02:37:26.144000
Earlean
elmlang
general
`Json.map2` takes a function as it's first parameter
2019-04-29T02:37:44.144400
Earlean
elmlang
general
ha, I got it. Thank you
2019-04-29T02:46:32.144700
Bethel
elmlang
general
How can I decode an array of objects of various shapes and I need to find just one exact shape in it and get that one. ``` let arr = [ { name: "Jon" }, { type: "Hot" }, { age: 16 } ] ``` and I would like to get the `age` object.
2019-04-29T02:58:37.146700
Bethel
elmlang
general
in brief, you cannot, as Elm lists have to contain all the same type.
2019-04-29T03:54:39.147300
Lynn
elmlang
general
you’ll need to use a CustomType to express the variations that you have
2019-04-29T03:54:56.147700
Lynn
elmlang
general
ah, sorry, read more carefully
2019-04-29T03:55:19.148100
Lynn
elmlang
general
`Decode.field "age" <http://Decode.int|Decode.int> |&gt; Decode.maybe |&gt; Decode.list |&gt; Decode.map (List.filterMap identity)`
2019-04-29T03:56:11.149100
Lynn
elmlang
general
i've been thinking about a possible "solution" to this for a while, but i'm not sure where to put it^^ it's not really polished yet either, as i've never taken the time to really write it down
2019-04-29T04:28:40.150200
Emilee
elmlang
general
To decode all content of the list, maybe <https://package.elm-lang.org/packages/elm/json/latest/Json-Decode#oneOf> could help
2019-04-29T04:29:05.150700
Millie
elmlang
general
If there is the possibility, I'd change the API model instead and go with a dict/object to tackle the root cause.
2019-04-29T04:31:06.150800
Millie
elmlang
general
There’s an additional point, actually: perhaps “custom types being comparable” is an XY-problem! Perhaps the most common reason for this request is people who wish to make a `Dict` or `Set` with custom types - in that case, them being comparable is a prerequisite for that to be possible. However, that’s not the only possible resolution - there is ongoing work for making hashmaps (and hashsets) a thing, and those would not require a `comparable` constraint.
2019-04-29T04:32:39.151000
Huong
elmlang
general
yeah, i also approached the issue differently. in my concept i'd try to move away from implicit typeclasses like `comparable` what i was thinking is that typeclasses always have the side effect of making things implicit, but elm a lot of the time is about making things explicit. when we look at a typical problem of "i want to have a sorted datastructure" the explicit method - passing the comparison function - has one of two poblems: • either we have to pass the function with every operation, which is clumsy and also error prone • or we have to put the function in the data structure, which makes it hard to work with in the model *but*: what if you could put the function in the type? i'm not exactly sure yet how this would be best implemented to maintain readability in elm, but if you could annotate your type with a function, you could have a `SortedDict (sortFunc : a -&gt; a -&gt; Ordering) a` or something. This would, I think, cover most cases where people with a background in haskell would reach for typeclasses, and still maintain explicitness. A major issue here is how it interacts with the existing syntax, and how to make it clear when we talk about a function type, and a function *as type* ^^' so yeah... also, i'm not yet sure how this could be abused, so that's a concern too.
2019-04-29T04:40:21.151200
Emilee
elmlang
general
are there any plans to add memoization to Elm?
2019-04-29T05:56:06.152300
Nana
elmlang
general
Not that I know of. Do you have a *specific* use-case where you feel like you would benefit from this? Seeing a concrete case with code would help (and would allow people to suggest workaround that apply to your case :slightly_smiling_face: )
2019-04-29T06:22:40.152400
Huong
elmlang
general
well, I have quite a lot of places where I sort/filter a long list of items, before displaying it in the view, for example as options in select boxes the issue with select boxes is that they also have an index which keeps track of which item the user is hovering over / has selected with up/down keys, so because of that `lazy` doesn't work
2019-04-29T06:28:44.152600
Nana
elmlang
general
I could of course manually cache the result in the model, but it'd be cleaner to have a memoization function I think
2019-04-29T06:30:43.153600
Nana
elmlang
general
If the input to the function changes, memoizing wouldn’t help either, would it? Or, no more than `lazy` would, I’m thinking?
2019-04-29T06:30:50.153800
Huong
elmlang
general
oh, wait, I can see how you’d do that
2019-04-29T06:31:11.154000
Huong
elmlang
general
so I'd memoize just the sorted/filtered list, but not the selection index
2019-04-29T06:31:48.154200
Nana
elmlang
general
so I’m assuming you have a long list of things, and a second variable that identifies a bunch of those things as being hovered or what not. Right, yeah.
2019-04-29T06:31:55.154400
Huong
elmlang
general
gotcha. Yeah, the current recommended workaround, after identifying that this is in fact a performance problem, would be caching it on the model
2019-04-29T06:32:57.155000
Huong
elmlang
general
Why is there no ternary operator in Elm? We have if..then..else, but elm-format insert a whole lot of space and newlines in it. ``` ternary : Bool -&gt; a -&gt; a -&gt; a ternary condition valueIfTrue valueIfFalse = if condition then valueIfTrue else valueIfFalse ```
2019-04-29T06:34:45.155700
Una
elmlang
general
and I think it'd be useful for a lot of similar things
2019-04-29T06:35:43.155900
Nana
elmlang
general
i hade similar problem, but for cache some precalculated data, so i got structure like: `{data:{..}, cache:{valid:Bool, cachedData:{...}}}` so then i had some functions that needs that cache, and they return not just result, but also updated element,
2019-04-29T06:45:17.156500
Liza
elmlang
general
but that not a case if You need that inside your view..
2019-04-29T06:45:39.156700
Liza
elmlang
general
or just before exit update function, you can validate cache and if needed recalculate it..
2019-04-29T06:46:14.156900
Liza
elmlang
general
I think validating the cache on every update could get expensive though? If it uses structural equality on big lists
2019-04-29T06:47:42.157100
Nana
elmlang
general
that is just `===` in js..
2019-04-29T06:48:12.157700
Liza
elmlang
general
or maybe not? because it first checks reference equality right?
2019-04-29T06:48:16.158000
Nana
elmlang
general
It first checks reference equality, yes
2019-04-29T06:48:27.158300
Huong
elmlang
general
for example - in my case that was SAT Shape - that had cached normals and projections, so if i change (by some function) position, with, or other component that impacts cache - it was set to “invalid”, and there was (LOT of) functions that not care about that cache - so most of cases that invalid cache can stay for long time, and then if i needed (some one came too near to collide ) cache was recalculated, and that stay like that again for long time..
2019-04-29T06:51:20.158500
Liza
elmlang
general
and validation of cache was just boolean stored in cache it self..
2019-04-29T06:51:37.158700
Liza
elmlang
general
so in your example - it would be just, set to false when change filter, and before exit update (if that list will be shown) check - do that prop (`cache.valid`) isn’t True
2019-04-29T06:53:01.159000
Liza
elmlang
general
this is one of the things I like in Vue, most calculations are done in "computed properties", which are memoized, and you can have computed properties which depend on other computed properties, which means that things only get recalculated when they really need to
2019-04-29T06:55:11.159200
Nana
elmlang
general
so - as result you not need to checks whole list, just manual invalidation each time when you make “cache braking” changes
2019-04-29T06:55:14.159400
Liza
elmlang
general
You could either have that `valid` flag, or write a wrapped around `update` which would look something like ```cacheHandler : Msg -&gt; Model -&gt; (Model, Cmd Msg) cacheHandler msg model = let original = model.source (updatedModel, cmds) = update msg model in if updatedModel.source == original then -- not changed (updatedModel, cmds) else ( { updatedModel | cache = calculate updatedModel.source }, cmds ) ```
2019-04-29T06:56:29.159600
Huong
elmlang
general
Since that check has a bypass for referential equality, things that don’t touch the `source` won’t trigger revalidation very very fast. If the reference did change, you still only revalidate the cache if structural equality _also_ says things have actually changed
2019-04-29T06:58:02.159800
Huong
elmlang
general
<@Huong> ah that's pretty neat, saving the original value in a closure. I was thinking I would have to store a duplicate in the model
2019-04-29T06:58:21.160000
Nana
elmlang
general
point with flag - is that you manually set it, and that can be changed only during some updates, that changes that list, so it will return it any way..
2019-04-29T06:58:22.160200
Liza
elmlang
general
doing the same with `valid : Bool` flag would mean having to recognise that if your code did something equivalent to `List.map identity source`, that should not invalidate the cache
2019-04-29T06:59:18.160400
Huong
elmlang
general
so - you any way will need to create wrappers around own data structure..
2019-04-29T07:00:20.160600
Liza
elmlang
general
and there will be “set / get / update”.. that will do all that stuff..
2019-04-29T07:01:14.160800
Liza
elmlang
general
but that depends on how many devs you have.. and how protected / transparent cache you would like to have
2019-04-29T07:01:44.161000
Liza
elmlang
general
we will hopefully be 2 devs soon, atm it's just me :smile: <@Huong>'s approach looks good, maybe it can be abstracted into a nice lib :thinking_face:
2019-04-29T07:17:36.161300
Nana
elmlang
general
<https://github.com/avh4/elm-format/issues/209>
2019-04-29T07:31:36.161500
Velia
elmlang
general
a "ternary operator" would be odd when `if` already behaves like an expression, rather than a statement but yeah hopefully elm-format will be updated some day
2019-04-29T07:40:30.161700
Nana
elmlang
general
Hello <@Huong> I tried these solutions, it doesn't work, due to failure in building elm-package-0.18
2019-04-29T08:13:25.161900
Calista
elmlang
general
```Please switch to using either the new project style and the new-install command or the legacy v1-install alias as new-style projects will become the default in the next version of cabal-install. Please file a bug if you cannot replicate a working v1- use case with the new-style commands. For more information, see: <https://wiki.haskell.org/Cabal/NewBuild> Resolving dependencies... Notice: installing into a sandbox located at /usr/local/elm/Elm-Platform/0.18/.cabal-sandbox Starting elm-package-0.18 Building elm-package-0.18 Failed to install elm-package-0.18 Build log ( /usr/local/elm/Elm-Platform/0.18/.cabal-sandbox/logs/ghc-7.10.3/elm-package-0.18-GAzqzqXmEIs4OwPrTLlD98.log ): cabal: Entering directory '/usr/local/elm/Elm-Platform/0.18/elm-package' Configuring elm-package-0.18... Warning: 'ghc-options: -threaded' has no effect for libraries. It should only be used for executables. Preprocessing executable 'elm-package' for elm-package-0.18.. Building executable 'elm-package' for elm-package-0.18.. [ 1 of 27] Compiling Utils.Paths ( src/Utils/Paths.hs, dist/dist-sandbox-90435201/build/elm-package/elm-package-tmp/Utils/Paths.o ) src/Utils/Paths.hs:15:27: Not in scope: ‘N.toFilePath’ src/Utils/Paths.hs:19:26: Not in scope: ‘Package.versiontoString’ Perhaps you meant one of these: ‘Package.versionToString’ (imported from Elm.Package), ‘Package.versionFromString’ (imported from Elm.Package) cabal: Leaving directory '/usr/local/elm/Elm-Platform/0.18/elm-package' cabal: Error: some packages failed to install: elm-package-0.18-GAzqzqXmEIs4OwPrTLlD98 failed during the building phase. The exception was: ExitFailure 1 elm-reactor-0.18-GWP7BE9OpskDnHmLhmsAmZ depends on elm-reactor-0.18 which failed to install.```
2019-04-29T08:13:58.162300
Calista
elmlang
general
I was wondering if `Elm.Foo.init({ element })` was also considered when they decided it should be `Elm.Foo.init({ node })` instead and why was that?
2019-04-29T09:04:26.168900
Maxwell
elmlang
general
presumably because they're called DOM nodes
2019-04-29T09:04:44.169400
Danika
elmlang
general
They're also called DOM elements.
2019-04-29T09:05:25.170000
Maxwell
elmlang
general
`&lt;a&gt;` is an element. A DOM node is a specific instantiation of an element
2019-04-29T09:05:43.170400
Huong