Say we want to spin off threads every so often, but we also need the ability to wait until they all go away before exiting the application.
In Haskell, we can do this naive thing:
main = do
count <- newTVarIO 0
let spawnThread action = do| -- sort function, optimized for lists | |
| -- TODO - profiling | |
| sortBy compare = head . head . dropWhile (isn't unsafeCoerce . drop 1) . group . iterate bubble | |
| where | |
| bubble [] = [] | |
| bubble [x] = [x] | |
| bubble (x:y:ys) = | |
| if compare x y == GT | |
| then y:(bubble (x:ys)) | |
| else |
| echo off | |
| echo ; set +v # > NUL | |
| echo ; function GOTO { true; } # > NUL | |
| GOTO WIN | |
| # On Unix, we need to explicitly invoke CLR executables with mono | |
| /usr/bin/env mono $@ | |
| exit 0 | |
| :WIN |
| struct S { | |
| S(int) {} | |
| S(const S&) = delete; | |
| }; | |
| int main() { | |
| auto a = S { 5 }; // no go | |
| S s {5}; // ok | |
| return 0; | |
| } |
| use std::str::CharRange; | |
| struct El<T> { | |
| ch : char, | |
| children : Trie<T> | |
| } | |
| pub struct Trie<T> { | |
| elements : Vec<El<T>>, | |
| data : Option<T> |
| x :: String | |
| Just (Just (x:[])) = Just (Just []) | |
| main :: IO () | |
| main = putStrLn x |
| #!/bin/bash | |
| set -ex | |
| if [ `uname` == 'Linux' ]; then | |
| PASTE=xclip\ -o | |
| OPEN=xdg-open | |
| else | |
| # Assume OSX | |
| PASTE=pbpaste |
| {-# LANGUAGE RecordWildCards #-} | |
| module Promise where | |
| import Control.Monad | |
| import Data.IORef | |
| import Data.Maybe | |
| data Status | |
| = Pending |
| // This object will hold all exports. | |
| var Haste = {}; | |
| /* Thunk | |
| Creates a thunk representing the given closure. | |
| If the non-updatable flag is undefined, the thunk is updatable. | |
| */ | |
| function T(f, nu) { | |
| this.f = f; | |
| if(nu === undefined) { |
| use std::ops::{Add, Sub}; | |
| #[derive(Copy, Debug)] | |
| pub struct Rect<T> { | |
| pub left: T, | |
| pub top: T, | |
| pub right: T, | |
| pub bottom: T | |
| } |
Say we want to spin off threads every so often, but we also need the ability to wait until they all go away before exiting the application.
In Haskell, we can do this naive thing:
main = do
count <- newTVarIO 0
let spawnThread action = do