Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an alias for a record in this case?

Tags:

alias

record

elm

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?

like image 571
benbro00002 Avatar asked Jan 26 '23 09:01

benbro00002


1 Answers

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
like image 105
Chad Gilbert Avatar answered Jan 27 '23 23:01

Chad Gilbert