Skip to content

Add mapValue#23

Open
hirataqdees wants to merge 1 commit intodafny-lang:masterfrom
hirataqdees:mapValue-func
Open

Add mapValue#23
hirataqdees wants to merge 1 commit intodafny-lang:masterfrom
hirataqdees:mapValue-func

Conversation

@hirataqdees
Copy link

This commit adds a function mapValue for mapping a function over values of a given map

This commit adds a function `mapValue` for mapping a function over
values of a given map
}

/* Map a function to the values of a map */
function method {:opaque} mapValue<K, V, V'>(f: V -> V', m: map<K, V>): (m':map<K, V'>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions:

Suggested change
function method {:opaque} mapValue<K, V, V'>(f: V -> V', m: map<K, V>): (m':map<K, V'>)
function method {:opaque} MapValues<K, V, V'>(f: V ~> V', m: map<K, V>): (m': map<K, V'>)
  • Pascal casing since that's what the style guide says:https://github.com/dafny-lang/libraries/blob/master/STYLE.md#naming-convention :)
  • You're already accounting for partial functions in your requires, but since you're declaring f to have type V -> V', that means f is a total function and its precondition is always just "true". V --> V' is the arrow type that allows for other non-trivial preconditions, and then V ~> V' is the even more general arrow type that allows for reads clauses as well. You'll have to add a reads clause to the function itself of course, something like reads set o | exists k in m.Keys :: o in f.reads(k).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants