# ValueSemantic protocol

**URL:** <https://forums.swift.org/t/valuesemantic-protocol/41686>\
**Category:** Discussion\
**Created:** [November 2, 2020, 3:53am UTC](https://forums.swift.org/t/valuesemantic-protocol/41686 "2020-11-02T03:53:26Z")\
**Posts on this page:** 1\
**Showing post:** 71

<div class="post-metadata">

**Author:** ![anandabits](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anandabits/32/355_2.png) [@anandabits](https://forums.swift.org/u/anandabits)\
**Post date:** [November 6, 2020, 4:45pm UTC](https://forums.swift.org/t/valuesemantic-protocol/41686/71 "2020-11-06T16:45:56Z")

</div>

> [@dabrahams](#):
>
> But then that would be a different type from an ordinary function type that we have today.

Chris was already talking about introducing something different than ordinary function types with `@actorSendable`.

> [@dabrahams](#):
>
> But a first-class language feature that makes a category of `pure` function types would be lots cleaner to use, would allow us to type check the composition of pure functions, and could handle `inout` .

I agree this would be great. Do you imagine that these functions would conform to `ValueSemantic`? Fwiw, I `inout` would work fine with my suggestion. Only mutable captures would need to be banned.

> [@dabrahams](#):
>
> You can do that without any language features

Sure, but then you lose all of the language support for function types.

> [@dabrahams](#):
>
> Oh, I think not, unless you want to say the behavior of the function is independent of its value! There's no way to compare the behaviors of two functions for equality.

I don't see why it is a problem to say the value of the function is related to source identity. If we take the C++ approach and view closures as syntactic sugar for [anonymous structs](https://forums.swift.org/t/anonymous-structs/31424) then equality becomes clear. It looks like @Joe_Groff [thinks this is a reasonable idea](https://forums.swift.org/t/pitch-protocol-based-actor-isolation/41677/47).

> [@dabrahams](#):
>
> once you get to built-in function types in Swift there's no way to control the semantics that they expose, and I don't think we'll ever be able to compare them reliably.

What specific problems do you see with the above approach?

> [@dabrahams](#):
>
> Yeah, sure, design away! That sounds great. Could get messy though; you might need to represent `safe` in the type system too.

Unfortunately I don't have time for this exercise right now. I hope we can have `ValueSemantic` function values someday though.

> [@Chris\_Lattner3](#):
>
> It is more precise to say that `Never` should conform to protocols without init and static requirements. I think that `ValueSemantics` is an example of this.

Agree.

> [@dabrahams](#):
>
> Stage 2: Allow `ValueSemantic` conformance to be inferred for tuples, structs, and enums of `ValueSemantic` -conforming types.
> 
> If that's what you mean, sure. I'm all for staging, although I don't see a _huge_ advantage in this case because stage 2 is pretty trivial.

I also think this inference should be supported from the start. I'm hoping Chris has something more in mind related to enforcing safety.

---

_[View the full topic](https://forums.swift.org/t/valuesemantic-protocol/41686)._
