# Newbie question: Can I mark functions as pure?

**URL:** <https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718>\
**Category:** Question\
**Created:** [January 11, 2024, 2:17am UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718 "2024-01-11T02:17:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![halloleo](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@halloleo](https://users.scala-lang.org/u/halloleo)\
**Post date:** [January 11, 2024, 2:17am UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718/1 "2024-01-11T02:17:55Z")

</div>

This might be totally obvious for everybody except me:

Despite Scala not being a pure language, can I mark specific functions as pure, so that the compiler tells me if I do state changes or IO in these functions?

(If I recall it correctly, [Nim](https://nim-lang.org/) can do this.)

---

<div class="post-metadata">

**Author:** ![jducoeur](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jducoeur/32/462_2.png) [@jducoeur](https://users.scala-lang.org/u/jducoeur)\
**Post date:** [January 11, 2024, 2:38am UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718/2 "2024-01-11T02:38:46Z")

</div>

Not yet. This sort of thing is a topic of active research (last I checked, anyway), and it might show up in the mainline language eventually, but it’s fairly challenging to add in a way that is both ergonomic and sufficiently powerful to be useful. (And general in a Scala-esque way.) Hopefully someday…

---

<div class="post-metadata">

**Author:** ![bishabosha](https://users.scala-lang.org/user_avatar/users.scala-lang.org/bishabosha/32/2567_2.png) [@bishabosha](https://users.scala-lang.org/u/bishabosha)\
**Post date:** [January 11, 2024, 8:13am UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718/3 "2024-01-11T08:13:58Z")

</div>

In scala 3 there is an experimental `pureFuns` import you can try: [Pure Function Syntax](http://dotty.epfl.ch/docs/reference/experimental/purefuns.html), note that it is only a syntax sugar, rather than any extra checks/guarantees

---

<div class="post-metadata">

**Author:** ![halloleo](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/h/ccd318/32.png) [@halloleo](https://users.scala-lang.org/u/halloleo)\
**Post date:** [January 30, 2024, 11:35am UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718/4 "2024-01-30T11:35:17Z")

</div>

> [@bishabosha](#):
>
> […][Pure Function Syntax](http://dotty.epfl.ch/docs/reference/experimental/purefuns.html)[…]

Thanks for the link. I hope _one day_ it will include extra checks! 😄

---

<div class="post-metadata">

**Author:** ![devlaam](https://users.scala-lang.org/user_avatar/users.scala-lang.org/devlaam/32/2246_2.png) [@devlaam](https://users.scala-lang.org/u/devlaam)\
**Post date:** [January 30, 2024, 2:00pm UTC](https://users.scala-lang.org/t/newbie-question-can-i-mark-functions-as-pure/9718/5 "2024-01-30T14:00:13Z")

</div>

I think this would be a very valuable addition to the language, once fully implemented. And, although it is still in the experimental corner, can we at least be sure the syntax will stable? Otherwise it does not make much sense using this upfront. (I’m not a fan of references to `language.experimental` in production code)
