workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
elmlang
|
general
|
Both key and value of a dict must a of _one_ specific type. I know now other way to achieve this, other with a new type that wraps multiple types.
|
2019-01-04T16:45:49.551300
|
Timika
|
elmlang
|
general
|
If `Dict` would allow multiple kinds of type as value at the same time, how would you know what type `Dict.get "key"` results in? :slightly_smiling_face:
|
2019-01-04T16:46:43.552300
|
Timika
|
elmlang
|
general
|
<@Nery> Are you asking in general or is there a specific problem you want to solve?
|
2019-01-04T16:47:28.553100
|
Monte
|
elmlang
|
general
|
<@Monte> is asking the real questions here :slightly_smiling_face:
|
2019-01-04T16:48:00.554200
|
Timika
|
elmlang
|
general
|
well a generally approach i take in other languages is to model my data based on a vocabulary of facts
and these usually go into a Dict-like structure but obviously the types vary
|
2019-01-04T16:48:01.554300
|
Nery
|
elmlang
|
general
|
so it would be great to be able to say "age" is Int
|
2019-01-04T16:48:30.554900
|
Nery
|
elmlang
|
general
|
Correct me if I’m wrong, but would that not be a record?
|
2019-01-04T16:48:42.555400
|
Timika
|
elmlang
|
general
|
to put the type on the _key_ itself, eg
|
2019-01-04T16:48:46.555500
|
Nery
|
elmlang
|
general
|
...which you can get with _records_, i realize but then i have to create a huge type taxonomy or something ... ie, that's cheating cos it's not on the key the type of the key is for that record only
|
2019-01-04T16:49:24.556600
|
Nery
|
elmlang
|
general
|
Can you give an example what you mean by “model my data based on a vocabulary of facts”?
|
2019-01-04T16:50:05.557300
|
Timika
|
elmlang
|
general
|
well here's an example... i want a function like
`isOldEnough()`
|
2019-01-04T16:50:21.557800
|
Nery
|
elmlang
|
general
|
`isOldEnough : Entity -> Boolean`
|
2019-01-04T16:50:35.558200
|
Nery
|
elmlang
|
general
|
```isOldEnough : { a | age : Int } -> Bool
isOldEnough { age } =
age >= 18```
|
2019-01-04T16:51:12.559000
|
Timika
|
elmlang
|
general
|
wherein isOldEnough could be defined as such:
`isOldEnough = get "age" Entity > 21`
|
2019-01-04T16:51:13.559200
|
Nery
|
elmlang
|
general
|
would be a way to do this with records
|
2019-01-04T16:51:20.559400
|
Timika
|
elmlang
|
general
|
gotcha
|
2019-01-04T16:51:26.559700
|
Nery
|
elmlang
|
general
|
Relevant to programming with maps <https://mobile.twitter.com/EvilHaskellTips/status/433449719226826752>
|
2019-01-04T16:51:36.560200
|
Kris
|
elmlang
|
general
|
then you can pass in every record with an `age` field.
|
2019-01-04T16:51:36.560300
|
Timika
|
elmlang
|
general
|
with an `_Int_``age` field
|
2019-01-04T16:51:59.561000
|
Nery
|
elmlang
|
general
|
cool
|
2019-01-04T16:52:01.561200
|
Nery
|
elmlang
|
general
|
Correct, yes.
|
2019-01-04T16:52:06.561400
|
Timika
|
elmlang
|
general
|
<@Kris> okay that evil tip has got me intrigued
|
2019-01-04T16:52:41.562300
|
Nery
|
elmlang
|
general
|
thx <@Timika>.. i know that's newbie stuff. i prolly should be in <#C192T0Q1E|beginners> on that question .. thank you
|
2019-01-04T16:53:06.562800
|
Nery
|
elmlang
|
general
|
No worries! Happy to help wherever I can! :slightly_smiling_face:
|
2019-01-04T16:53:32.563300
|
Timika
|
elmlang
|
general
|
Yeah, cake! :slightly_smiling_face:
|
2019-01-04T16:55:42.563800
|
Timika
|
elmlang
|
general
|
another pesky question...
what's the significance of requiring `age` to be defined in record after record
why couldn't age simply be defined as Int w/o marrying it to a record
are there strongly typed PLs that allow stuff like this.
it seems rather silly or redundant to have to keep re-defining `age` across N records as an Int
(i assume haskell makes you do the same thing?)
|
2019-01-04T16:59:00.565900
|
Nery
|
elmlang
|
general
|
I don’t understand your question, but you can just write that function as an `Int -> Bool` and call it as `f myRecord.age`
|
2019-01-04T17:00:41.568300
|
Kris
|
elmlang
|
general
|
Haskell doesn’t really have records, so nope : p
|
2019-01-04T17:00:55.568900
|
Kris
|
elmlang
|
general
|
but what if my logic is based on not just age, eg
`canRideThisRide : Entity -> Bool`
...where in you have to be 10 or older and your height has to be greater than 1.5m, say...
|
2019-01-04T17:02:36.571400
|
Nery
|
elmlang
|
general
|
so i have `age`, an Int, and `height`, a Float, say
|
2019-01-04T17:02:53.571800
|
Nery
|
elmlang
|
general
|
That works the same way as with my example code. You can _match_ on multiple fields.
|
2019-01-04T17:03:22.572400
|
Timika
|
elmlang
|
general
|
Are you trying to be super generic here? Or could `Entity` be a record that has all the fields you want:
```
type alias Entity =
{ age : Int
, height : Float
, name : String
, ...
}
```
|
2019-01-04T17:04:06.573300
|
Carman
|
elmlang
|
general
|
ah i like that <@Carman>
would that be acceptable approach or .. an anti-pattern..?
|
2019-01-04T17:05:00.574400
|
Nery
|
elmlang
|
general
|
Then you could say:
```
canRideThisRide : Entity -> Bool
canRideThisRide entity =
entity.age > 10 && entity.height < 1.5
```
|
2019-01-04T17:05:00.574500
|
Carman
|
elmlang
|
general
|
i mean that's basically what i'm after <@Carman>
|
2019-01-04T17:05:34.575400
|
Nery
|
elmlang
|
general
|
i want to define a _vocabulary_
|
2019-01-04T17:05:40.575800
|
Nery
|
elmlang
|
general
|
It would become an anti-pattern as soon as you have fields that are not used by all kinds of entities and then get a default value that makes no sense.
|
2019-01-04T17:05:50.576300
|
Timika
|
elmlang
|
general
|
NOT a taxonomy of types
|
2019-01-04T17:05:52.576400
|
Nery
|
elmlang
|
general
|
I'd say that's the standard way to design structures. As your business rules get more complex you can get fancier to eliminate impossible states
|
2019-01-04T17:05:59.576500
|
Carman
|
elmlang
|
general
|
ah <@Timika> that seems a problem
|
2019-01-04T17:06:24.576800
|
Nery
|
elmlang
|
general
|
can they just be defaulted to Empty/Null/what-have-you?
|
2019-01-04T17:07:16.577900
|
Nery
|
elmlang
|
general
|
Unknown
|
2019-01-04T17:07:27.578200
|
Nery
|
elmlang
|
general
|
You could make them `Maybe`s. But I would consider a record with just `Maybe` values an anti-pattern. But as always, you have to make your own trade-offs that make sense to you and the problem you’re trying to solve.
|
2019-01-04T17:08:12.579100
|
Timika
|
elmlang
|
general
|
yeah i guess my issue is that this seems pretty basic
|
2019-01-04T17:08:35.579700
|
Nery
|
elmlang
|
general
|
so i have a sense i'm missing something
|
2019-01-04T17:08:40.580000
|
Nery
|
elmlang
|
general
|
Could it be that you’re trying to do some game-engine stuff? :slightly_smiling_face:
|
2019-01-04T17:08:49.580200
|
Timika
|
elmlang
|
general
|
hahaha that would be more fun than what i'm doing
|
2019-01-04T17:08:58.580600
|
Nery
|
elmlang
|
general
|
i'm basically just doing business data processing stuff
|
2019-01-04T17:09:13.581200
|
Nery
|
elmlang
|
general
|
Elm doesn’t have that many language features
|
2019-01-04T17:09:20.581600
|
Kris
|
elmlang
|
general
|
like load a bunch of entities and then render them - basic stuff like that
|
2019-01-04T17:09:26.581900
|
Nery
|
elmlang
|
general
|
but to be able to just deal w/ facts like "age" and "height" seems pretty fundamental
so, since Dicts don't really make this natural, it seems _records_ are the way to go
well, more specifically, a _single_ record like Entity seems the way to go
|
2019-01-04T17:10:34.583500
|
Nery
|
elmlang
|
general
|
but then having say 100 fields that are all Maybe doesn't sound right
so i feel like i'm stuck between a rock and a hard place
|
2019-01-04T17:11:13.584400
|
Nery
|
elmlang
|
general
|
It depends on what the business rules of your system are. Are there some combinations of missing/present data that are invalid?
|
2019-01-04T17:13:20.587000
|
Carman
|
elmlang
|
general
|
not necessarily or minimally
after all is just to render
|
2019-01-04T17:13:43.587500
|
Nery
|
elmlang
|
general
|
so if a fact isn't present then it just doesn't need to render
|
2019-01-04T17:13:51.587900
|
Nery
|
elmlang
|
general
|
If all the Maybes are independent, it could be that you're just dealing with highly uncertain data
|
2019-01-04T17:14:29.588600
|
Carman
|
elmlang
|
general
|
well today it's well-known but i'm worried that as new writers want to come into the data system they'll end up breaking my code if i don't make everything Maybe
|
2019-01-04T17:15:12.590000
|
Nery
|
elmlang
|
general
|
The compiler will tell them if they need to add a Maybe
|
2019-01-04T17:16:23.590700
|
Carman
|
elmlang
|
general
|
If all the values are guaranteed to be there today then I wouldn't bring in Maybe
|
2019-01-04T17:16:53.591200
|
Carman
|
elmlang
|
general
|
they're serving up from back end code (no elm)
|
2019-01-04T17:17:06.591500
|
Nery
|
elmlang
|
general
|
if i don't make them Maybe.. they could break me overnight
|
2019-01-04T17:17:24.591800
|
Nery
|
elmlang
|
general
|
if only i could freeze time... : )
|
2019-01-04T17:17:37.592200
|
Nery
|
elmlang
|
general
|
Elm doesn't trust data that comes from APIs. If you're decoding JSON, it will tell you if the data is not in the right shape
|
2019-01-04T17:18:28.593100
|
Carman
|
elmlang
|
general
|
That seems to be your core problem. You’re reading data from a source that changes at-will. How could you ever work with data from such a source? This goes way beyond types.
|
2019-01-04T17:19:49.594900
|
Timika
|
elmlang
|
general
|
the source has the guarantee that all the facts are of the right type
like age is Int, height is Float, etc...
|
2019-01-04T17:20:33.595400
|
Nery
|
elmlang
|
general
|
it just won't guarantee which facts you will get across the board
|
2019-01-04T17:20:50.595800
|
Nery
|
elmlang
|
general
|
Ah, so all the facts are optional in the API?
|
2019-01-04T17:21:04.596400
|
Carman
|
elmlang
|
general
|
i'd say if i didn't make that assumption i'd be making myself unnecessarily brittle and easily breakable
|
2019-01-04T17:21:27.597200
|
Nery
|
elmlang
|
general
|
like my customers want access to their data in all cases
|
2019-01-04T17:21:58.598000
|
Nery
|
elmlang
|
general
|
like if i only have a guy's first name or last name they want to see that
|
2019-01-04T17:22:09.598400
|
Nery
|
elmlang
|
general
|
not only see it if i just have his first or last name only (for example)
|
2019-01-04T17:22:19.598900
|
Nery
|
elmlang
|
general
|
you might want to use a more general data structure then
|
2019-01-04T17:23:32.599800
|
Lashawnda
|
elmlang
|
general
|
i think that's what i'm looking for @luke
|
2019-01-04T17:23:52.600300
|
Nery
|
elmlang
|
general
|
but what is it if it's not a Dict or record(s)
|
2019-01-04T17:24:04.600600
|
Nery
|
elmlang
|
general
|
then it's time to model it with a custom type :slightly_smiling_face:
|
2019-01-04T17:24:26.601200
|
Lashawnda
|
elmlang
|
general
|
but how .. i mean i want something like a heterogenous Dict .. is there a good pattern (ie, custom type) to get that kind of data structure?
|
2019-01-04T17:24:55.602100
|
Nery
|
elmlang
|
general
|
The initial idea with a `Dict` and the custom type that encapsulates different types in one type seems one solution.
|
2019-01-04T17:24:58.602200
|
Timika
|
elmlang
|
general
|
ah yeah that sounds like a good start
|
2019-01-04T17:25:27.602800
|
Lashawnda
|
elmlang
|
general
|
<@Timika> i think you're right that initial pitch you have that's probably my best best
|
2019-01-04T17:25:33.603000
|
Nery
|
elmlang
|
general
|
bet
|
2019-01-04T17:25:35.603200
|
Nery
|
elmlang
|
general
|
cool i'm going to work with that for a while and see how it plays out
|
2019-01-04T17:25:46.603500
|
Nery
|
elmlang
|
general
|
really appreciate the help
|
2019-01-04T17:25:49.603700
|
Nery
|
elmlang
|
general
|
<more cakes> : )
|
2019-01-04T17:26:06.604000
|
Nery
|
elmlang
|
general
|
So, I think I came up with something
|
2019-01-04T17:35:14.604200
|
Huong
|
elmlang
|
general
|
I am quite late to the party but if you haven't already tried that I can recommend the `airbnb` eslint config. It's also opinated but has less weird things like the semi colons in `standard`
|
2019-01-04T17:38:06.604500
|
Freda
|
elmlang
|
general
|
<https://www.npmjs.com/package/eslint-config-airbnb>
|
2019-01-04T17:40:17.604700
|
Freda
|
elmlang
|
general
|
<@Lynne> you mentioned wanting to use `Tree.Zipper` with a root-less forest of trees earlier - I realized that it wouldn't be super-hard to make that possible, and it would provide more consistent behaviour for `prepend` and `append`, too, so, here you go: <https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/Tree-Zipper#fromForest>
|
2019-01-04T17:42:21.606300
|
Huong
|
elmlang
|
general
|
Need help on calling multiple function on a list while passing down the new list to the next function, I have abour 15 functions to call and apply filters and code is getting too large, so here is the example updatedRearAxleWeightFitlerList =
(uiModel.selectedFilterBullets, model.truckList)
|> filterBySalesStatus
|> filterByYear
|> filterByMake
|> filterByModel
|> filterBySleeperRoof
|> filterBySleeperBunk
|> filterByEngineMake
|> filterByTransType
|> filterBySuspension
|> filterByBodyType
|> filterByRearAxleType
|> filterByTruckType
|> filterByFleetCode
|
2019-01-04T19:09:24.608200
|
Ron
|
elmlang
|
general
|
is there a way to list those functions in a List and map over that list call each func and passdown the result to the next func call ?
|
2019-01-04T19:10:22.609400
|
Ron
|
elmlang
|
general
|
Yeah, there is. Need help finding it?
|
2019-01-04T19:10:58.610800
|
Niesha
|
elmlang
|
general
|
Oh, that would be great, because I have 20 more filters to apply
|
2019-01-04T19:11:30.611500
|
Ron
|
elmlang
|
general
|
jesus
|
2019-01-04T19:11:37.611800
|
Danika
|
elmlang
|
general
|
You could a) extract the filter functions into `(a -> Bool)` and then it's rather easy to compose them
|
2019-01-04T19:11:53.612200
|
Niesha
|
elmlang
|
general
|
or b) your `filterByX` are of type `List a -> List a`, in which case you wanna `foldl (>>) [filterByX, filterbyY]` (or `(<<)`)
|
2019-01-04T19:13:12.613600
|
Niesha
|
elmlang
|
general
|
thanks, I tried foldl, it didnt work, probably I didn't do it right, let me give a try again.
|
2019-01-04T19:15:30.614400
|
Ron
|
elmlang
|
general
|
Wait, I don't think `>>` is the right way to go here
|
2019-01-04T19:16:14.614800
|
Niesha
|
elmlang
|
general
|
<https://klaftertief.github.io/elm-search/?q=(a%20-%3E%20a)%20-%3E%20(a%20-%3E%20a)%20-%3E%20(a%20-%3E%20a)>
|
2019-01-04T19:16:15.615000
|
Niesha
|
elmlang
|
general
|
you need this function, doesn't seem to exist yet
|
2019-01-04T19:16:23.615400
|
Niesha
|
elmlang
|
general
|
Nah, that's `>>`, the search just doesn't find it
|
2019-01-04T19:17:28.615700
|
Niesha
|
elmlang
|
general
|
Oh hey is this like hoogle?
|
2019-01-04T19:18:35.615900
|
Danika
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.