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
{-# LANGUAGE ForeignFunctionInterface #-} | |
module RawSocket where | |
import Foreign.C | |
import Network.Socket | |
foreign import ccall "setsockopt" | |
setsockopt_cstr :: CInt -> CInt -> CInt -> CString -> CInt -> IO CInt |
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
-- important: compile with -threaded | |
import Control.Concurrent.STM | |
import Control.Applicative | |
-- |Wait for STM action specified amount of time and return value of action or default value if action times out | |
stmTimeout' :: Int -> a -> STM a -> IO a | |
stmTimeout' microseconds defVal f | |
= registerDelay microseconds |
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
{-# LANGUAGE RankNTypes #-} | |
-- |Maybe without algebraic data types and typeclasses, including monadic ops | |
newtype Maybe' a = Maybe' (forall b. b -> (a -> b) -> b) | |
just' :: a -> Maybe' a | |
nothing' :: Maybe' a | |
fromMaybe' :: a -> Maybe' a -> a | |
maybe' :: b -> (a -> b) -> Maybe' a -> b |