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
:set -i./src -i./bin | |
-- Read GHCI commands from the file whose name is | |
-- in the GHCIRC environment variable | |
:def _load const(System.Environment.getEnvironment>>=maybe(return"")readFile.lookup"GHCIRC") | |
:_load | |
:undef _load | |
:def hoogle \str -> return $ ":! hoogle --count=15 \"" ++ str ++ "\"" | |
-- <http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/dot-squashed.ghci641> | |
let { redir varcmd = case break Data.Char.isSpace varcmd of { (var,_:cmd) -> return $ unlines [":set -fno-print-bind-result","tmp <- System.Directory.getTemporaryDirectory","(f,h) <- System.IO.openTempFile tmp \"ghci\"","sto <- GHC.Handle.hDuplicate System.IO.stdout","GHC.Handle.hDuplicateTo h System.IO.stdout","System.IO.hClose h",cmd,"GHC.Handle.hDuplicateTo sto System.IO.stdout","let readFileNow f = readFile f >>= \\t->length t `seq` return t",var++" <- readFileNow f","System.Directory.removeFile f"]; _ -> return "putStrLn \"usage: :redir <var> <cmd>\"" } } | |
:def redir redir |
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 PatternGuards #-} | |
{-# LANGUAGE ViewPatterns #-} | |
module ViewPatterns where | |
import Data.List | |
data EMail = EMail User Domain deriving Show | |
type User = String | |
type Domain = String | |
view :: String -> Maybe EMail |
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 Tree a = Leaf | Branch a (Tree a) (Tree a) deriving Show | |
// | |
// isEmpty :: Tree a -> Bool | |
// isEmpty Leaf = True | |
// isEmpty _ = False | |
// | |
// insert :: Ord a => a -> Tree a -> Tree a | |
// insert e Leaf = Branch e Leaf Leaf | |
// insert e b@(Branch e' l r) | |
// | e < e' = Branch e' (insert e l) r |
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 scala.actors._ | |
import scala.actors.Actor._ | |
import java.net.InetAddress | |
sealed abstract class DnsMessage | |
case class DnsRequest(name: String, sender: Actor) extends DnsMessage | |
case class DnsResponse(name: String, address: Option[InetAddress]) extends DnsMessage | |
class DnsResolver extends Actor { | |
def act() { |
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 <sys/time.h> | |
#include <sys/resource.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct rlimit rlimit_t; | |
int main(void) | |
{ | |
rlimit_t *r = (rlimit_t *) malloc(sizeof(struct rlimit)); |
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 BiFold where | |
import Prelude hiding (foldr, foldl) | |
-- http://d.hatena.ne.jp/nobsun/20100824/1282617326 | |
bifold :: ((a, c) -> b -> (a, c)) -> (a, c) -> [b] -> (a, c) | |
bifold f (a, c) (b:bs) = (a'', c'') | |
where (a', c'') = f (a, c') b | |
(a'', c') = bifold f (a', c) bs | |
bifold _ z _ = z |
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.Applicative | |
import Control.Exception | |
import Control.Monad | |
import Control.Monad.Loops | |
import System.Environment | |
import System.IO | |
main :: IO () | |
main = 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 TypeOperators #-} | |
{-# LANGUAGE UnicodeSyntax #-} | |
module Arrow where | |
import Control.Arrow | |
import Control.Applicative (pure) | |
import Control.Category | |
import Control.Category.Unicode ((∘), (⋙)) | |
import Prelude hiding (id, (.)) | |
import qualified Prelude |
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 Fibs where | |
import StreamProc | |
import Control.Arrow | |
test = take 10 $ runSP fibs [0..] | |
fibs :: SP a Integer | |
fibs = put 0 fibs' | |
where fibs' = put 1 $ liftA2 (+) fibs fibs' |
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 ExistentialQuantification #-} | |
module Main where | |
import Data.Char (ord) | |
data Exists r = forall a. Exists a (a -> r) | |
x2 :: Exists Int | |
x2 = Exists (3 :: Int) id | |
xapp :: Exists a -> a |