This file contains 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
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 |
This file contains 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
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") |
This file contains 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
loop :: Integer -> Integer -> IO () | |
loop time steps = do | |
timeNow <- getCPUTime | |
threadDelay $ max 0 $ fromIntegral $ (steps * 1000000) - ((timeNow - time) `div` 1000000) | |
loop time (steps + 1) |
This file contains 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
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE RankNTypes #-} | |
module Logic where | |
-- Quantifier | |
data Q a | |
-- Predicate | |
= P (a -> Bool) | |
-- Universal Quantifier |
This file contains 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
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) |