Search code examples
functordhall

Dhall - map on record field


I have a type

let Resource = \(a : Type) ->
  { name : Text
  , type : Text
  , properties : a
  }

and a function foo : InstanceTemplateProperties -> Properties.

I need to create a function Resource InstanceTemplateProperties -> Resource Properties.

I could write it as

\(p : Resource InstanceTemplateProperties) ->
  { name = p.name
  , type = p.type
  , properties = foo p.properties
  } : Resource Properties

but it looks really cumbersome. Is there an easier and more idiomatic way to do this?


Solution

  • You can use // to merge the updated properties into the original.

    (\p : Resource InstanceTemplateProperties) ->
      p // {properties = foo p.properties)