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 DeriveFunctor #-} | |
module Main where | |
import Control.Monad | |
import Control.Monad.Free | |
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
module QuickSortWithDL where | |
import Data.Monoid | |
data DL a = DL ([a] -> [a]) | |
instance Monoid (DL a) where | |
mempty = DL ([] ++) | |
DL f `mappend` DL g = DL (f . g) | |
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
#include <errno.h> | |
#include <fcntl.h> | |
#include <netdb.h> | |
#include <netinet/in.h> | |
#include <netinet/tcp.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> |
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 TypeSynonymInstances, FlexibleInstances #-} | |
module Main where | |
import Control.Monad | |
import Control.Monad.Error | |
import Control.Monad.Trans.RWS.Strict | |
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
module Main where | |
import Control.Monad | |
import Prelude hiding (putChar, getChar) | |
import qualified System.IO as IO | |
import Test.QuickCheck | |
---------------------------------------------------------------- | |
-- Our DSL |
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 | |
import Control.Monad | |
import Control.Monad.Free | |
import Prelude hiding (putChar, getChar) | |
import qualified System.IO as IO | |
import Test.QuickCheck | |
---------------------------------------------------------------- | |
-- Our DSL |
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
---------------------------------------------------------------- | |
-- Free Monad example agaist RWH 15.8 | |
-- | |
-- Original code: http://ideone.com/F49k71 | |
import Control.Applicative | |
import Control.Monad.Free | |
import System.IO (Handle, IOMode(..), stdout) | |
import qualified System.IO as IO | |
import System.IO.Unsafe |
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
data Bin a = Bin a a deriving Show | |
data List a = Nil | Cons a (List (Bin a)) deriving Show | |
len :: List a -> Int | |
len Nil = 0 | |
len (Cons _ t) = 1 + 2 * len t |
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 MultiParamTypeClasses, FlexibleInstances #-} | |
import Data.Map (Map) | |
import qualified Data.Map as M | |
import Data.Maybe | |
data Trie m ks v = Trie (Maybe v) (m (Trie m ks v)) | |
class FiniteMap m k where | |
empty :: m k v |
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 MultiParamTypeClasses, FlexibleInstances #-} | |
import Data.Map (Map) | |
import qualified Data.Map as M | |
import Data.Maybe | |
data Trie m k v = Trie (Maybe v) (m k (Trie m k v)) | |
class FiniteMap m k where | |
empty' :: m k v |