- Enter GHCi (via Stack)
stack ghci
- Enable functions to break on exceptions
| {-# LANGUAGE ScopedTypeVariables #-} | |
| module Main where | |
| import Network (listenOn, withSocketsDo, accept, PortID(..), Socket) | |
| import Control.Concurrent (forkIO) | |
| import Control.Exception (handle, IOException) | |
| import Control.Monad (liftM) | |
| import System.IO (hSetBuffering, hPutStr, hClose, hGetContents, BufferMode(..), Handle, readFile) | |
| import Debug.Trace |
| import System.IO | |
| import Network.Socket | |
| import Network (PortID(..)) | |
| import System.Environment | |
| import Control.Concurrent | |
| import Control.Monad | |
| import Control.Monad.Fix (fix) | |
| import Data.Char | |
| import Data.List.Split | |
| import System.IO.Error |
| import Control.Concurrent | |
| import Control.Exception | |
| setInterval :: Int -> a -> (a -> IO a) -> IO () | |
| setInterval microsecs a action = do | |
| mvar <- newEmptyMVar | |
| _ <- setInterval' microsecs a mvar action | |
| takeMVar mvar |
| {-# OPTIONS_GHC -Wall -fno-warn-unused-binds #-} | |
| {-# LANGUAGE CPP #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE IncoherentInstances #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| #if __GLASGOW_HASKELL__ >= 708 | |
| {-# LANGUAGE RoleAnnotations #-} | |
| #endif |
| {------------------------------------------------------------------------------- | |
| Discussion of ContT in terms of callbacks | |
| For an alternative exposition, see | |
| <http://www.haskellforall.com/2012/12/the-continuation-monad.html>. | |
| -------------------------------------------------------------------------------} | |
| {-# OPTIONS_GHC -Wall #-} | |
| import Control.Exception |
| {-# LANGUAGE CPP #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| #if __GLASGOW_HASKELL__ >= 710 | |
| {-# LANGUAGE AllowAmbiguousTypes #-} | |
| #endif | |
| -- | Lightweight checked exceptions |
| {-# LANGUAGE TypeFamilies, KindSignatures, DataKinds, TypeOperators, GADTs, MultiParamTypeClasses, FlexibleInstances, GeneralizedNewtypeDeriving, OverlappingInstances, ScopedTypeVariables, FlexibleContexts #-} | |
| import Control.Applicative | |
| import Control.DeepSeq | |
| import qualified Control.Exception as E | |
| -- Closed type family, needs GHC HEAD. | |
| type family Minus (e :: *) (es :: [*]) :: [*] where | |
| Minus e '[] = '[] | |
| Minus e (e ': es) = Minus e es |