Skip to content

Instantly share code, notes, and snippets.

data Heap a = Tree !Int !a (Heap a) (Heap a) | Leaf
empty :: Heap a
empty = Leaf
push :: Heap a -> Int -> a -> Heap a
push tree@(Tree p n l r) p2 n2 =
if p2 < p
then Tree p2 n2 tree Leaf
else Tree p n r (merge (Tree p2 n2 Leaf Leaf) l)
import Random as R
main = (\(_,_,stuff,msgs) -> flow down (asText stuff :: map plainText msgs)) <~
foldp stepFSM
(("Waiting",0),("Waiting",0),(0,0),[])
(R.floatList ((fps 1) `sampleOn` constant 3))
stepFSM rnds ((stateA,seqA),(stateB,seqB),(recA,recB),messages) =
let rs = map (\n -> floor (n*10.0)) rnds
ra = head rs
main = showFSM <~ foldp send ("SENT","-> ","SENT") (fps 1)
showFSM (a,b,c) = plainText <| a ++ b ++ c
send _ (stateA,packet,stateB) =
case packet of
"* " -> ("SENT","-> ",stateB)
"-> " -> (stateA," -> ",stateB)
" -> " -> (stateA," ->",stateB)
" ->" -> (stateA," *","SEND")
loop :: Integer -> Integer -> IO ()
loop time steps = do
timeNow <- getCPUTime
threadDelay $ max 0 $ fromIntegral $ (steps * 1000000) - ((timeNow - time) `div` 1000000)
loop time (steps + 1)
@ZacharyKamerling
ZacharyKamerling / gist:5925021
Last active December 19, 2015 08:19
Quantifiers
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Logic where
-- Quantifier
data Q a
-- Predicate
= P (a -> Bool)
-- Universal Quantifier