Skip to content

Instantly share code, notes, and snippets.

View robstewart57's full-sized avatar

Rob Stewart robstewart57

View GitHub Profile
@robstewart57
robstewart57 / newtype laziness
Created November 9, 2012 14:00
newtype vs data in haskll
Prelude> data D = D Int
Prelude> let f (D i) = "ok"
Prelude> f undefined
"*** Exception: Prelude.undefined
Prelude> newtype D = D Int
Prelude> let f (D i) = "ok"
Prelude> f undefined
"ok"
@robstewart57
robstewart57 / AsyncTimeouts.hs
Created December 3, 2012 13:28
Timeouts in async haskell package
{-# LANGUAGE DeriveDataTypeable #-}
import Control.Concurrent (threadDelay)
import Control.Exception (Exception,throw)
import Control.Monad (void)
import Control.Concurrent.Async (Async,race,wait,withAsync)
import Data.Typeable (Typeable)
data ThreadTimeoutException = ThreadTimeoutException
deriving (Show, Typeable)
@robstewart57
robstewart57 / spin_failure_model.pml
Last active December 10, 2015 15:29
spin failure model
mtype = { FISH , RESCHEDULE , SCHEDULE , SCHEDULEREQ , SCHEDULEAUTH , ACK , NOWORK , SENDFAILED , PING } ; // message payload types
mtype = { ONNODE , INTRANSITION }; // spark.status types
typedef Node {
chan inChan = [50] of {mtype, chan } ;
bool hasSpark;
bool waitingFish;
bool waitingSchedAuth;
bool dead;
};
@robstewart57
robstewart57 / ping_pong_ltl_claim
Last active December 10, 2015 16:39
A ping-pong linear temporal logic never claim in promela that fails to verify
mtype = { PING , PONG , INFO } ;
typedef Node {
chan inChan = [50] of {mtype } ;
bool receivedInfo;
};
Node nodes[2];
active proctype Master() {
@robstewart57
robstewart57 / spin_never_verification.txt
Created January 8, 2013 14:49
odd verification claim
/////////////
// Before
syntax check
the model contains 7 never claims: never_6, never_5, never_4, never_3, never_2, never_1, never_0
spin -a -o3 model.pml
the model contains 7 never claims: never_6, never_5, never_4, never_3, never_2, never_1, never_0
only one claim is used in a verification run
choose which one with ./pan -N name (defaults to -N never_0)
gcc -DMEMLIM=1024 -O2 -DXUSAFE -DNOREDUCE -w -o pan pan.c
./pan -m10000 -a -c1 -N never_6
@robstewart57
robstewart57 / typeclassstate.hs
Last active December 14, 2015 11:39
Haskell type class with state
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Concurrent.MVar
class Foo a where
mkFoo :: IO a
readFoo :: a -> IO Int
operateOnFoo :: a -> IO ()
newtype Bar = Bar (MVar Int)
-- API Module: Transport API as typeclass
class Transport t where
createTransport :: IO (Either IOException t)
newEndPoint :: t -> IO (Either (TransportError NewEndPointErrorCode) EndPoint)
closeTransport :: t -> IO ()
-- Separate module: TCP implementation
newtype TCPTransport = TCPTransport (N.HostName,N.ServiceName,MVar TransportState,TCPParameters)
@robstewart57
robstewart57 / table-new-exporter.org
Created March 27, 2013 13:52
Org mode's new exporter for tables
..........
..........
@robstewart57
robstewart57 / three CCI-tcp runs
Created May 14, 2013 14:00
3 runs identifying CCI_EVENT_NONE in tcp implementation
### FIRST RUN
cci: only keeping CTP list: (null)
cci: In sock post_load
cci: In tcp post_load
cci: entering ctp_sock_init
cci: querying interface en0 info with socket ioctls and ethtool...
cci: adding device [en0] (transport sock)
cci: exiting ctp_sock_init
cci: entering ctp_tcp_init
cci: querying interface en0 info with socket ioctls and ethtool...
-module(ammunition_factory).
-export([repeat_explosion/2,time_bomb/1]).
time_bomb(0) -> exit("boom!");
time_bomb(N) ->
timer:sleep(1000),
time_bomb(N-1).
repeat_explosion(0,N) ->
_Pid = spawn_monitor(fun() -> time_bomb(N) end),