ST monad declaration syntax

I recently started exploring the core Hackage libraries, and there’s a repeating idiom that I don’t understand. Here is an example from the ST module :

instance Monad (ST s) where {-# INLINE (>>=) #-} (>>) = (*>) (ST m) >>= k = ST (\ s -> case (ms) of { (# new_s, r #) -> case (kr) of { ST k2 -> (k2 new_s) }}) 

In particular, I do not understand (# new_s, r #) . I assume that the second hash refers to an unreasonable value, but the rest is a mystery to me (something related to the "new state", presumably).

+7
haskell st-monad
source share
1 answer

(# x, y, z #) is an unprocessed tuple with three elements. See "8.2.2. Unboxed Tuples" at https://downloads.haskell.org/~ghc/6.8.3/docs/html/users_guide/primitives.html .

The rest is just an implementation of the state.

+7
source share

All Articles