Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapValue #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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
@@ -48,6 +48,17 @@ module Maps {
m'
}

/* 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