workspace
stringclasses
4 values
channel
stringclasses
4 values
text
stringlengths
1
3.93k
ts
stringlengths
26
26
user
stringlengths
2
11
elmlang
general
Its a web server, that receives a musical score in the form of a fairly chaotically structured `String`, and then turns it into audio, and continuously diffs and modifies that audio as updated scores come in.
2019-04-09T11:01:48.919300
Ashton
elmlang
general
Im a Haskell scrub, so in hindsight I would have structured the `String` I need to parse better. Everything was pretty ad-hoc as I wanted to include more information.
2019-04-09T11:02:23.920300
Ashton
elmlang
general
one neat thing I imagine you could use typeclasses for is so that you don't have to manually "assemble" json decoders/encoders
2019-04-09T11:02:55.921100
Nana
elmlang
general
Either way, there are lots of `fromText :: Text -> Either Error Thing` functions in the project, that form a heirarchy that feels very much like a `view` or `update` heirarchy in Elm.
2019-04-09T11:03:00.921300
Ashton
elmlang
general
so if you have a "jsonable" typeclass, you could just write a decoder/encoder for each type, and then have a generic function that automatically encodes/decodes any structure
2019-04-09T11:05:25.921700
Nana
elmlang
general
also, being able to use custom types as keys for Dict/Set would be nice :smile:
2019-04-09T11:06:31.921900
Nana
elmlang
general
What do you do when you need to decode something in two different ways in two different contexts?
2019-04-09T11:11:11.922100
Ashton
elmlang
general
no idea (never used haskell/typeclasses :D)
2019-04-09T11:11:54.922300
Nana
elmlang
general
Anybody written an algorithm to highlight search terms in text? Given some search string and another string of text, it would break up the text and insert spans with a highlight color in every place where there is a match.
2019-04-09T11:14:24.923500
Crissy
elmlang
general
`newtype` is one way of doing that using different typeclasses with the same data: <https://wiki.haskell.org/Newtype>
2019-04-09T11:15:12.923600
Shenita
elmlang
general
you basically wrap the data in a single argument type and then give that wrapper type different typeclass instances
2019-04-09T11:16:25.924400
Shenita
elmlang
general
some combination of `Regex.find` and `String.slice` would work I think
2019-04-09T11:16:29.924600
Virgie
elmlang
general
Here's mine: ``` highlight : Attribute msg -&gt; String -&gt; String -&gt; Html msg highlight attribute substring string = let regex = Misc.toRegex substring matches = Regex.find regex string |&gt; List.map (\match -&gt; span [ attribute ] [ text match.match ]) rest = Regex.split regex string |&gt; List.map text in span [] (List.Extra.interweave rest matches) ```
2019-04-09T11:17:00.925200
Nana
elmlang
general
Indeed. Was hoping someone else might have done the hard work before I write it myself... :slightly_smiling_face:
2019-04-09T11:17:01.925500
Crissy
elmlang
general
(it's using Regex to get case-insensitivity)
2019-04-09T11:18:25.925600
Nana
elmlang
general
`Misc.toRegex` looks like this: ``` toRegex : String -&gt; Regex.Regex toRegex string = if string == "" then Regex.never else Regex.fromStringWith { caseInsensitive = True, multiline = False } string |&gt; Maybe.withDefault Regex.never ```
2019-04-09T11:19:10.925800
Nana
elmlang
general
I check for `string == ""` because that causes a runtime error otherwise!
2019-04-09T11:19:56.926000
Nana
elmlang
general
let me know if you make any improvements :slightly_smiling_face:
2019-04-09T11:20:41.926200
Nana
elmlang
general
Very nice, thank you Simon.
2019-04-09T11:20:55.926400
Crissy
elmlang
general
<@Ashton> you just revert to using decoding/encoding primitives just as in Elm ; the difference is that when the transition is obvious from JSON to Haskell and vice-versa, you don't need to write your decoders (thus reducing boilerplate tremendously).
2019-04-09T11:22:51.926600
Antonette
elmlang
general
Thanks for your comments <@Antonette>, its given me an interesting perspective on typeclasses. Regarding your last comment, “…thus reducing boilerplate”. Arent typeclasses a kind of boilerplate?
2019-04-09T11:58:26.927900
Ashton
elmlang
general
Like, `deriving (Eq)` is just not a thing I have to do in Elm. In your json example, its not like I dont have to write a decoder, its just that, Instead of writing it as `decoder =` and then using that value, I have to write an instance of the typeclass.
2019-04-09T11:59:11.928100
Ashton
elmlang
general
Same code in two difference places, as far as I can tell.
2019-04-09T11:59:18.928300
Ashton
elmlang
general
(sorry, I was away for a while :sweat_smile:)
2019-04-09T12:12:03.928600
Antonette
elmlang
general
The thing is, if you're not `deriving (Eq)` you don't get the benefit of being usable with all the functions that need an `Eq` instance...
2019-04-09T12:12:55.928800
Antonette
elmlang
general
...imagine having to re-invent all those functions for all your datatypes... yuck.
2019-04-09T12:13:10.929000
Antonette
elmlang
general
<@Ashton> typeclasses ought to always reduce the amount of code I guess `Eq` is a special case though since Elm has built-in equality checking
2019-04-09T12:14:00.929200
Nana
elmlang
general
And the reason why you don't have to do this in `Elm` is because everything is natively "equalable"... for better and worse. Try to test if a `Value` is equal to another... (spoiler alert, they always are equal to one another, whatever their content)
2019-04-09T12:14:12.929400
Antonette
elmlang
general
Now, one pain point you can have with `Elm` is that you don't get to make your own `comparable` instances, thus can't use your own types as keys for a `Dict` for example.
2019-04-09T12:16:30.929600
Antonette
elmlang
general
(and now I have to leave from work... will gladly return to this conversation later if you're interested :wink:)
2019-04-09T12:16:56.929800
Antonette
elmlang
general
and also if you create your own monad/functor/monoid/whatever you don't have to define `map2`,`map3`,`concat`,`andThen` etc. although how often do you really do that, besides if you're a package author?
2019-04-09T13:00:18.930300
Nana
elmlang
general
&gt; I don't think it's helpful to say "just ditch Elm if you disagree with X" or have the narrative of "trying to make X in Elm is bad" because of all of the extra reasons you would choose to work with something. this is frequently done in the community. Elm is very niche and targeted to what it does, and if you don't accept that you are in for some frustration. weigh in the cost of learning this tool for a set of use cases, vs learning another one that is applicable to a broader set of use cases (even if less polished)
2019-04-09T13:05:04.930700
Bebe
elmlang
general
<@Antonette> I'm not sure the Value equality you mention is right, I just checked this: ``` &gt; a = E.string "banana" &lt;internals&gt; : E.Value &gt; b = E.string "phone" &lt;internals&gt; : E.Value &gt; a /= b True : Bool &gt; (a == b) False : Bool &gt; b = E.string "banana" &lt;internals&gt; : E.Value &gt; (a == b) True : Bool &gt; a /= b False : Bool ``` Seems to work as expected
2019-04-09T13:18:01.931100
Bebe
elmlang
general
even with an object, it looks like it did a deep equal? ``` &gt; a = E.object [("banana", E.string "phone")] &lt;internals&gt; : E.Value &gt; b = E.object [("banana", E.string "apple")] &lt;internals&gt; : E.Value &gt; (a == b) False : Bool &gt; a /= b True : Bool &gt; b = E.object [("banana", E.string "phone")] &lt;internals&gt; : E.Value &gt; (a == b) True : Bool &gt; a /= b False : Bool ```
2019-04-09T13:18:41.931300
Bebe
elmlang
general
I just pushed. Sooner than feared :wink:
2019-04-09T13:36:08.931500
Dede
elmlang
general
This push adds a `subscriptions` entry to Descriptors, which should address your immediate question. It also puts a lot more functionality into `Session` generally.
2019-04-09T13:36:45.931700
Dede
elmlang
general
Maybe it's been reworked since I did that experiment (it was in 0.18), or maybe it was because our objects were more deeply nested ; thanks for updating us, I'll try and replicate your findings with examples more akin to what I had at the time.
2019-04-09T14:09:10.932200
Antonette
elmlang
general
Yeah <@Antonette>, but then it just seems to be that languages with a native equality are better.
2019-04-09T15:53:15.932700
Ashton
elmlang
general
In my opinion.
2019-04-09T15:53:22.932900
Ashton
elmlang
general
I guess Im kind of missing custom dictionary keys. That would be nice. I wonder if theres any problems I am not seeing by just having automatic comparability for custom types.
2019-04-09T15:55:20.933100
Ashton
elmlang
general
Here's a question that might help: is `True` greater than or lower than `False`?
2019-04-09T15:57:00.933300
Antonette
elmlang
general
I think that doesnt make sense, but then, isnt that a matter of comparability, not equality?
2019-04-09T15:58:42.933500
Ashton
elmlang
general
<@Antonette> `true &gt; false` and `true + true &gt; true` if you ask JS :wink:
2019-04-09T16:04:13.933700
Nana
elmlang
general
<@Ashton> comparability is what makes Dict lookups fast, and it's required to make the trees they are based on
2019-04-09T16:06:14.934900
Nana
elmlang
general
Re: no more variable shadowing. Would you say :thumbsup: “my code is better as a result”, or :thumbsdown: “it causes just as many problems as it purports to address”?
2019-04-09T16:06:30.935200
Leoma
elmlang
general
Is there a write-up on what it is trying to address?
2019-04-09T16:09:12.936500
Emilee
elmlang
general
I was already avoiding variable shadowing back in 0.18 after getting bitten by a shadowing bug so the 0.19 changes just meant the compiler enforced my personal style :slightly_smiling_face:
2019-04-09T16:10:52.937000
Carman
elmlang
general
it's pretty common for linters to have warnings for shadowing, it's generally seen as bad style
2019-04-09T16:12:14.937700
Nana
elmlang
general
The flip side is an “anti-shadowing” bug. That is, with MORE variables in scope, you have a higher likelyhood of accidentally using the wrong variable at a point. Am I wrong to see that as an advantage of shadowing? I was just bitten by this and id took many days to solve.
2019-04-09T16:12:49.937900
Leoma
elmlang
general
I have never been bitten by a shadowing bug.
2019-04-09T16:13:04.938100
Leoma
elmlang
general
shadowing variable names is a sign you are doing too much in one function. Many nested case expressions for example: break them into functions. Erlang codebases are a good example of how effective this is. If you are shadowing in the case of matching on a `Maybe/Result`, I often prefix the name with an `m` or `e`
2019-04-09T16:15:31.938400
Isaiah
elmlang
general
I also tend to write many small functions rather than large ones with nested `case` and `let ... in` statements so have few variables in scope.
2019-04-09T16:15:40.938600
Carman
elmlang
general
Occasionally I'll use point-free style to avoid having to name an argument that might clash with some other identifier
2019-04-09T16:17:13.939000
Carman
elmlang
general
Well, I’m not 100% sure what “too much in one function” means in a pure language. But I see that refactoring out chucks of code can fix the the problem.
2019-04-09T16:17:52.939200
Leoma
elmlang
general
shadowing might not cause bugs for yourself, but it can be confusing for other people to read
2019-04-09T16:19:28.940100
Nana
elmlang
general
Has anyone shared common code between multiple elm applications by listing the directory in `elm.json`'s `source-directories` like so? `"../../Common"`? Does this work?
2019-04-09T16:20:35.941500
Isaiah
elmlang
general
and when others recommend against something, Elm forbids it :male-police-officer:
2019-04-09T16:20:46.941600
Nana
elmlang
general
Same as what others have said about small scopes. Having two things of the same type in the same scope creates the possibility of mixing them up. One value of each type eliminates this category of error entirely (which is, often not possible, but its my rule of thumb).
2019-04-09T16:22:24.941900
Ashton
elmlang
general
I guess the way I see it is, if I have `|&gt; (\x -&gt; x + y)` it’s clear to me where I think x and y are coming from. And possibly I want the function inline to remind me of its implementation. Elm gives me 2 choices. 1 is rename x, where I can accidentally do `|&gt; (x_ -&gt; x + z)`, OR it forces me to refactor out a function where maybe I didn’t want to.
2019-04-09T16:22:55.942100
Leoma
elmlang
general
It works, as long as you install the required dépendencies.
2019-04-09T16:24:20.942400
Velia
elmlang
general
Anyway. Seems I’m a minority in this perspective. That’s cool. I just wanted to see what others thought after having some time with this feature/limitation. :beers:
2019-04-09T16:25:57.942600
Leoma
elmlang
general
That’s the approach taken here: <https://github.com/Skinney/elm-git-install>
2019-04-09T16:26:45.943000
Lorilee
elmlang
general
I agree it can be awkward sometimes though
2019-04-09T16:27:52.943400
Nana
elmlang
general
Thanks
2019-04-09T16:28:00.943700
Isaiah
elmlang
general
I wouldn't say mixing up vars is eliminated as a class of errors! This kind of thing happens for me: ```let x = 5 -- original x value x_ = x + fudge -- changed it later! in x + x -- forgot to change x to x_ here. ```
2019-04-09T16:28:24.944200
Lindsey
elmlang
general
Yes and I hate using that when you are sharing between different repos.
2019-04-09T16:30:17.946400
Lindsey
elmlang
general
What happens is you no longer know what version of the 'common' you are on anymore.
2019-04-09T16:30:43.947000
Lindsey
elmlang
general
Probably the way to go is with git submodules, which I also hate.
2019-04-09T16:30:55.947400
Lindsey
elmlang
general
For instance I might have project A and B both using common. I change common in order to have a new feature in B, but now I've broken A.
2019-04-09T16:32:08.948800
Lindsey
elmlang
general
I think you should give `x_` a more descriptive name instead of just appending `_` though
2019-04-09T16:32:23.949200
Nana
elmlang
general
In general, I think appending a `_` to the end of a variable to get around the shadowing restriction is a poor solution. As you showed, it's still easy to use the wrong one.
2019-04-09T16:32:26.949400
Carman
elmlang
general
Ideally you're instead narrowing your scope, extracting functions, and passing values in as arguments.
2019-04-09T16:32:36.949800
Carman
elmlang
general
Yes, but then your’e confronted with the hardest part of programming. Naming the function. :cold_sweat:
2019-04-09T16:34:06.951400
Leoma
elmlang
general
true true... but that kind of practice is up to old fashioned programmer discipline - its not a problem that shadow elimination solves automatically.
2019-04-09T16:34:21.952000
Lindsey
elmlang
general
I currently have a single (large, 14k loc) application bundle with internal routing (and url changes), but I wonder if breaking parts of it out (e.g. login and registration, redeeming invite codes) into separate applications would give me any huge benefit. Right now, most of the application requires the user to be authenticated, and the login/register pages (along with the internal routing) add non-trivial complexity to both the codebase and the models used. If the server handles most of the routing, and I am able to break some of it out into smaller, single purpose applications that store any shared state in sessionStorage, I wonder how much easier it might be to work with.
2019-04-09T16:36:28.953800
Isaiah
elmlang
general
True. Good point. The compiler eliminates the most egregious cases but programmers can still use poor practices* to simulate shadowing, thus bringing back all the associated issues. _*poor practices - appending `_` is not necessarily bad in all cases, I'm generalizing here_
2019-04-09T16:37:40.953900
Carman
elmlang
general
does anyone know how to create a custom fuzzer for strings which does not create empty strings?
2019-04-09T16:38:26.954400
Vilma
elmlang
general
`conditional` was removed, but would be a good fit for 0.18. <https://package.elm-lang.org/packages/elm-community/elm-test/latest/Fuzz#conditional>
2019-04-09T16:46:16.954500
Millie
elmlang
general
So perhaps `Fuzz.string` and `map` combined to replace empty string values with a constant string
2019-04-09T16:47:32.954700
Millie
elmlang
general
Or combine/append `Fuzz.char` and `Fuzz.string`
2019-04-09T16:51:21.955300
Millie
elmlang
general
Thanks <@Krista> and <@Velia> ! A new patch version has been released that should fix the issue!
2019-04-09T17:29:43.955500
Tamra
elmlang
general
We've been trying out a monorepo at work with two projects sharing data structures and requests and stuff, it's still in the early stages but is working well so far. There are some problems that arise from the monorepo, like not wanting to deploy app A in CI when only app B's code changed , gitlab has a nice solution where you can set which pipelines to run based on what folders the code changed in.
2019-04-09T18:23:09.956000
Augustus
elmlang
general
Another alternative I started on previously was a dockerized <http://package.elm-lang.org|package.elm-lang.org> that we could host private packages on, but from the discussion on 0.19 support for elm-github-install it seemed like the core team would hate it
2019-04-09T18:31:25.956200
Augustus
elmlang
general
creating packages and git submodules is definitely not what I had in mind. I just wanted an easy way to split a single-page app into multiple apps. It's still one application, just spread across multiple elm bundles.
2019-04-09T19:39:10.956500
Isaiah
elmlang
general
brilliant! I’ll try it today. your work let newbie to be able to write SPA , that’s unbelievable! thanks again!
2019-04-09T20:01:56.956700
Shantell
elmlang
general
you definitely want a mono-repo approach.
2019-04-09T20:55:38.957800
Myrna
elmlang
general
Are there any concerns with creating a personal Log module, for example, that exposed `log = Debug.log`, and when it was time to go to production, one just sets `log = always identity`? Or is Elm implying that the way to do a release is to a) branch b) remove all Debug.log statements c) tag and deploy ?
2019-04-09T21:43:56.959300
Leoma
elmlang
general
having a personal log module seems like a good solution if you're using `Debug.log` widely
2019-04-09T21:46:47.960100
Earlean
elmlang
general
Ya, it seems to me that if I ever get to the point where I’m logging too much, or have too many logging statements, I can still easily remove them.
2019-04-09T21:48:05.961300
Leoma
elmlang
general
Thanks for the kind words. Let me know how it goes. This was a quick update today, so there may be documentation holes and/or errors :wink:
2019-04-09T21:51:42.961400
Dede
elmlang
general
it works! even though I have a long way to go to fully understand what you have done. that’s magic. :rolling_on_the_floor_laughing:
2019-04-09T23:10:52.962100
Shantell
elmlang
general
Given this custom type, how could I create a function with this type signature?
2019-04-09T23:45:52.962400
Kenny
elmlang
general
<@Kenny> why the nested Maybes?
2019-04-09T23:47:27.963100
Earlean
elmlang
general
The extra Maybe might be a bit of a red herring for the question. I have a spot that can optionally take a message that gets fired on some event - that message can then take an optional message that it will fire in its update
2019-04-09T23:50:30.966000
Kenny
elmlang
general
i think that knowing this would help: `NestedMsgs : NestedMsg -&gt; BaseMsg` then it's a matter of having enough `Maybe.map`s :slightly_smiling_face:
2019-04-09T23:54:06.967900
Ruthann
elmlang
general
and some decision about what default to use if you have a `Nothing`
2019-04-09T23:54:39.968600
Earlean
elmlang
general
If I had a nothing I would just return a nothing
2019-04-09T23:57:56.969000
Kenny
elmlang
general
`(Maybe NestedMsg -&gt; NestedMsg)` if you passed `Nothing` to this function, what value of `NestedMsg` would you return?
2019-04-09T23:59:19.970800
Earlean
elmlang
general
<@Ruthann> I don't think I fully understand - to simply convert a NestedMsg to a BaseMsg I was expecting to say NestedMsgs somenestedmsg - I might look more into maybe.map
2019-04-09T23:59:47.971200
Kenny
elmlang
general
``` convertMsg : Maybe (Maybe NestedMsg -&gt; NestedMsg) -&gt; Maybe (Maybe BaseMsg -&gt; BaseMsg) convertMsg maybeNestedMsg = case maybeNestedMsg of Just maybeNestedfunction -&gt; ??? This is where I got stuck -- maybeNestedfunction -- &gt;&gt; Maybe.map NestedMsgs Nothing -&gt; Nothing ```
2019-04-10T00:00:04.971500
Ruthann