7 ms·
> This particular formulation allows structures to be changed while they are being constructed, but makes them immutable once construction is complete. Equival
by gioele 12y ago
> This particular formulation allows structures to be changed while they are being constructed, but makes them immutable once construction is complete.
Equivalent to the following Ruby?
a = "abc"
a.upcase!
a.freeze
a.downcase! # => RuntimeError: can't modify frozen String
- ufo 12y agoKind of but the important difference is that Ruby checks that at runtime instead of giving a compile time error.
- okasaki 12y agoso like this? import Control.Monad.ST import Data.STRef main = do let n = runST $ do n <- newSTRef 5 modifySTRef n (+ 10) readSTRef n modifySTRef n (+ 10) {- ^^^^^^ Couldn't match expected type IO t0 with actual type ST s0 () In the expression: main When checking the type of the IO action main -} print n
- ufo 12y agoYes, more like that. There are some extra wrinkles they could add with subtyping, record types, etc but its still going to be a silly thing to patent.
- deleted 12y ago[deleted]
- chc 12y agoThat isn't a type constraint — it's a value-level behavior enforced at runtime.