Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which programming languages support constant methods?

Which programming languages other than C++ support the concept of a constant class method? That is, what languages allow the programmer to constrain a method in such a way that it is guaranteed not to change the state of an object to which the method is applied?

Please provide examples or references in your answer.

like image 769
Derek Mahar Avatar asked Mar 23 '10 17:03

Derek Mahar


2 Answers

Haskell, since it's purely functional.

Actually, every value/method is constant in Haskell even though mutable state/IO can be modelled through a mathematical construct called monad.

like image 101
Dario Avatar answered Sep 27 '22 23:09

Dario


All purely functional languages are all const by default because purely functional languages have no state to be changed.

like image 43
Peter Alexander Avatar answered Sep 27 '22 22:09

Peter Alexander