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
-- Dynamic programming from Algorithm Introduction | |
module Stations where | |
import Control.Arrow | |
import Data.Array | |
import Data.Function.Memoize | |
data Line = Line { | |
_size :: Int | |
, _e1 :: Int |
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
module Main where | |
-- Pearls of Functional Algorithm Design | |
-- Section 8: Unravelling greedy algorithms | |
import Control.Exception | |
import Control.Applicative | |
main :: IO () | |
main = handle handler $ do |
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 GADTs #-} | |
module Gadt where | |
import Control.Arrow (first) | |
import Data.Char | |
---------------------------------------------------------------- | |
data Dynamic where |
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 BangPatterns #-} | |
{-# LANGUAGE CPP, ForeignFunctionInterface #-} | |
-- ghc --make -O2 -funbox-strict-fields -threaded -rtsopts SimpleServer.hs | |
import Network.Socket | |
import System.Environment (getArgs) | |
import Control.Concurrent | |
import Control.Monad | |
import Foreign |
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 GADTs #-} | |
module Main where | |
import Control.Monad | |
import Control.Monad.RWS.Strict | |
import Control.Monad.Trans.Error | |
import Control.Monad.Operational.Simple | |
import Prelude hiding (putChar, getChar) | |
import qualified System.IO as IO |
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 GADTs #-} | |
module Main where | |
import Control.Monad | |
import Control.Monad.Operational.Simple | |
import Prelude hiding (putChar, getChar) | |
import qualified System.IO as IO | |
import Test.QuickCheck |
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
type world = unit | |
type 'a io = world -> 'a | |
(* write : string -> unit io *) | |
let write str = fun () -> print_string str | |
(* read : string io *) | |
let read = read_line | |
(* run : a' io -> 'a *) |
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
import System.Posix.IO | |
import System.Posix.Terminal | |
readPassword :: IO String | |
readPassword = do | |
echoOn <- getTerminalAttributes stdInput | |
let echoOff = withoutMode echoOn EnableEcho | |
fdWrite stdOutput "Password: " | |
setTerminalAttributes stdInput echoOff Immediately | |
pass <- getLine |
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
-- % cabal install PSQueue | |
-- % ghci Dijkstra.hs | |
-- > dijkstra sample A | |
-- [(A,0,A),(D,4,A),(E,7,D),(C,8,E),(B,9,E)] | |
module Dijkstra where | |
import Control.Applicative hiding (empty) | |
import Data.List (unfoldr) | |
import Data.Maybe (fromJust) |
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 CPP | |
, ForeignFunctionInterface | |
, BangPatterns | |
, GeneralizedNewtypeDeriving #-} | |
#include <poll.h> | |
import Foreign.C.Types (CInt(..), CShort(..), CChar(..)) | |
import Foreign.Marshal.Alloc | |
import Foreign.Ptr (Ptr, castPtr, plusPtr) |