# Specifying Function Contract

**URL:** <https://discourse.julialang.org/t/specifying-function-contract/108983>\
**Category:** Internals & Design\
**Created:** [January 18, 2024, 8:24pm UTC](https://discourse.julialang.org/t/specifying-function-contract/108983 "2024-01-18T20:24:57Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [January 22, 2024, 5:23pm UTC](https://discourse.julialang.org/t/specifying-function-contract/108983/6 "2024-01-22T17:23:11Z")

</div>

The thread [Case Study: Method Invalidations caused by Pkg.jl with Julia 1.11](https://discourse.julialang.org/t/case-study-method-invalidations-caused-by-pkg-jl-with-julia-1-11/109038/11) ended up answering a problem here:

> [@Case Study: Method Invalidations caused by Pkg.jl with Julia 1.11](https://discourse.julialang.org/t/case-study-method-invalidations-caused-by-pkg-jl-with-julia-1-11/109038/11):
>
> I think a nice example of that `(::Any == ::Any)::Bool` which is perfectly fine in Base as the only return type from `==` in Base, but then any symbolic representation of code turns `==` into something symbolic and every code with a type-unstable `==` recompiles due to Symbolics existing. The problem is, if `==` “should” only ever return a Boolean (which I don’t think should be the case, there’s other counter examples), then we should get an error for violating the rule.

Specifically here, given the importance of Symbolics in the Julia ecosystem, the meaning of function names doesn’t always match the mechanical use of those functions. Setting a contract that requires `==` to return a `Bool` would be problematic for them.

I am certainly no Core Developer, so I don’t pretend to know the tradeoffs for serving different use cases. But I do wonder if it would be possible to use Cassette.jl to transform all `(F)(args...) where F` to `(F)(SymbolicCall(), args...)` that could have its own contract, so that “normal” use cases could benefit from the correctness checks that function contracts could provide.

---

_[View the full topic](https://discourse.julialang.org/t/specifying-function-contract/108983)._
