This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let state = ref 0;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (!): ‘a ref -> ‘a | |
| !state;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (:=) : ‘a ref -> ‘a -> unit | |
| state := 1;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type 'a Ref = { mutable value : 'a } | |
| let (!) (r : 'a Ref) = r.value | |
| let (:=) (r : 'a Ref) (v:'a) = r.value <- v;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let gen f = | |
| let i = ref 0 | |
| fun () -> (i := !i + 1; f !i);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let sq x = x*x;; | |
| let g = gen sq;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let hd (x::xs) = x;; | |
| let tl (x::xs) = xs;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let stream init = | |
| let state = ref init | |
| let put x = (state := (!state)@[x]) | |
| let get () = let r = hd !state | |
| state := tl !state | |
| r | |
| let isEmpty () = !state = [] | |
| (put, get, isEmpty);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let spawn f = (new Thread(new ThreadStart(f))).Start();; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let getLock () = new ReaderWriterLock();; | |
| let acquireWrite (lock:ReaderWriterLock) = lock.AcquireWriterLock(-1);; | |
| let releaseWrite (lock:ReaderWriterLock) = lock.ReleaseWriterLock();; | |
| let acquireRead (lock:ReaderWriterLock) = lock.AcquireReaderLock(-1);; | |
| let releaseRead (lock:ReaderWriterLock) = lock.ReleaseReaderLock();; | |
| let upgrade (lock:ReaderWriterLock) = lock.UpgradeToWriterLock(-1);; | |
| let downgrade (lock:ReaderWriterLock) cookie = lock.DowngradeFromWriterLock(cookie);; |