Making record type arguments easier to maintain #102
AttilaMihaly
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
Am I missing the proposal here? Also I actually don't find the extensible record to be that tedious, especially if you are allowed to assign it to a type alias and then use the type alias. |
Beta Was this translation helpful? Give feedback.
1 reply
-
How would this transpile to more restrictive languages? Would it result in an explosion of traits (one for each function)? Another approach is to define the function arguments independently, which both makes it apparent exactly what's needed and makes the logic most universally accessible. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider the following use-case:
While the function
logic
declares its input asMyInput
it really only uses one of the 27 fields the type has so it's requiring much more data to be available then what it really needs. This is a common modeling problem which leads to difficulties around testing because you need to pass in many dummy values. It also makes evolving types more difficult because if we just look at the type signature it seems that changing any fields will impact this function while in reality it wouldn't for most fields.Elm (and Morphir) provides extensible records to get around this. You can change the type signature to:
This tells the compiler that the input needs to have a
bar
field but it doesn't limit the rest of the record structure. This is great and very accurate but also very tedious. It's also redundant since the compiler could infer this anyway. On the other hand we usually do want to derive this from the definition ofMyInput
but the language doesn't help us with that.What we would ideally want is the combination of the two:
myInput
as a value of typeMyInput
.myInput
to be of type{ e | bar : Int }
.This would provide the best of both worlds and seems to be possible to implement in the Morphir tooling.
Beta Was this translation helpful? Give feedback.
All reactions