I have a question about records: Lets say I have a function that takes a record, like this:
getId : { file | id : String } -> String
getId file = file.id
I could pass in something like this: { id = "abcd", name = "hi.txt"}
because it's got an id
. All good so far. My question is: could I create an alias for the "file" in the function type signature? What would the syntax for that be?
You could define an alias for this extensible record called WithID
like this:
type alias WithID a = { a | id : String }
Now you can update the signature of getId
like so:
getId : WithID a -> String
getId file = file.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With