 }
 
 public class STM<A> {
-    private var run: (Transactions -> (A, Transactions))
-    
-    private init(_ x: A) {
-        run = {return (x, $0)}
-    }
-    
-    private init(_ f: Transactions -> (A, Transactions)) {
-        run = f
-    }
-    
-    private class func ret(val:A) -> STM {
+    private var run: _STM<A?>
+    
+    private init(_ x: _STM<A?>) {
+        run = x
+    }
+    
+    private class func ret(val: _STM<A?>) -> STM {
         return STM(val)
     }
-
-}
+}
+
+public func returnM<A> (x:A) -> STM<A> {
+    return STM.ret(returnM(x))
+}
+
 
 /**
 Performs transaction. Warning: Swifts type system does not allow to explicitly mark function as pure.


//MARK: writeTVar
public func writeTVar<T: TVarProtocol> (tvar: TVar<T>, val: T) -> STM<()> {
    return STM({ ((), _writeTVar(tvar, val, $0)) })
}

public func writeTVar<T> (tvar: TVarArray<T>, val: [T]) -> STM<()> {
    return STM({ ((), _writeTVar(tvar, val, $0)) })
}

public func writeTVar<K,V> (tvar: TVarDictionary<K,V>, val: [K:V]) -> STM<()> {
    return STM({ ((), _writeTVar(tvar, val, $0)) })
}

//MARK: modifyTVar

    }
}

//---------------------//
//MARK: Extensions
//---------------------//
extension Int: TVarProtocol {
    public func copy() -> TVarProtocol {
        return self
