Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / debugging-in-haskells-ghci.md
Created October 26, 2016 21:54
Debugging in Haskell's GHCi

Debugging in Haskell's GHCi

  • Enter GHCi (via Stack)
stack ghci
  • Enable functions to break on exceptions
@caiorss
caiorss / Main.hs
Created October 26, 2016 21:52 — forked from DuoSRX/Main.hs
simplistic haskell web server
{-# 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
@caiorss
caiorss / haskell-cheat-sheets-functions.md
Created October 26, 2016 21:49 — forked from vpayno/haskell-cheat-sheets-functions.md
Haskell Cheat Sheets - Functions
@caiorss
caiorss / HaskellStyleGuide.md
Created October 26, 2016 21:46 — forked from cidevant/HaskellStyleGuide.md
Haskell Style Guide

Haskell Style Guide

This is a short document describing the preferred coding style for this project. I've tried to cover the major areas of formatting and naming. When something isn't covered by this guide you should stay consistent with the code in the other modules.

Formatting

@caiorss
caiorss / TimerRecursion.hs
Created October 26, 2016 21:44 — forked from homam/TimerRecursion.hs
Timer, setInterval in Haskell
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
@caiorss
caiorss / CheckedRevisited.hs
Created October 26, 2016 19:26 — forked from edsko/CheckedRevisited.hs
Lightweight checked exceptions in Haskell without `unsafeCoerce`
{-# OPTIONS_GHC -Wall -fno-warn-unused-binds #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if __GLASGOW_HASKELL__ >= 708
{-# LANGUAGE RoleAnnotations #-}
#endif
@caiorss
caiorss / callbacks.hs
Created October 26, 2016 19:19 — forked from edsko/callbacks.hs
Alleviating callback hell in Haskell
{-------------------------------------------------------------------------------
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
@caiorss
caiorss / Checked.hs
Created October 26, 2016 19:15 — forked from edsko/Checked.hs
Lightweight checked exceptions in Haskell
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
#if __GLASGOW_HASKELL__ >= 710
{-# LANGUAGE AllowAmbiguousTypes #-}
#endif
-- | Lightweight checked exceptions
@caiorss
caiorss / gist:ba5879f70fafb99cbc886d7efcd9017b
Created October 26, 2016 19:15 — forked from chpatrick/gist:7358782
Haskell 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