Skip to content

Instantly share code, notes, and snippets.

gdb ./a.out
GNU gdb 6.3.50-20050815 (Apple version gdb-1820) (Sat Jun 16 02:40:11 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done
(gdb) run
@NathanHowell
NathanHowell / A.cmm
Last active December 21, 2015 22:09
#include <Cmm.h>
getInfoTable (P_ a)
{
W_ clos, info, type;
clos = UNTAG(a);
info = %GET_STD_INFO(clos);
return (info);
}
@NathanHowell
NathanHowell / thread-fixio.hs
Created August 10, 2013 20:24
Passing a threadID to a thread
import Control.Concurrent
import System.IO
t :: ThreadId -> IO ()
t tid = print ("mah thread", tid)
main :: IO ()
main = do
_tid <- fixIO (forkIO . t)
threadDelay 100000000
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.Base
import Control.Monad.Trans.Control
import Control.Concurrent.MSem as MSem
withMSem :: (MonadBaseControl IO m, Integral i) => MSem i -> m a -> m a
withMSem = liftBaseOp_ . MSem.with
@NathanHowell
NathanHowell / chan.hs
Last active December 11, 2015 19:19 — forked from scan/chan.hs
import Control.Concurrent.Chan (Chan, newChan)
import qualified Data.Map as M
import Control.Concurrent.STM
import Control.Monad.Trans (MonadIO, liftIO)
import GHC.Conc (unsafeIOToSTM)
type Id = Integer
getOrCreateChannel :: (MonadIO m) => Id -> TVar (M.Map Id (Chan a)) -> m (Chan a)
getOrCreateChannel cid t = liftIO . atomically $ do
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveDataTypeable #-}
module AlphaHeavy.Exception
( setDefaultUncaughtExceptionHandler
, lastException
, uncaughtExceptionHandler
) where
import Control.Exception (Exception(..), SomeException(..))
import Data.Array.ST
import Control.Monad.ST
import Control.Monad.Reader
type Env = String
type ReaderST s = ReaderT Env (ST s)
foo :: ReaderST s [Int]
foo = do
int someCall(int x)
{
return x * x;
}
@NathanHowell
NathanHowell / gist:2633184
Created May 8, 2012 06:58 — forked from mwotton/gist:2633129
fun with forall
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Forall where
import Control.Applicative
import Data.Aeson
import Control.Monad
data Bar = Bar Int
data Baz = Baz Int Int
@NathanHowell
NathanHowell / value-promotion.hs
Last active September 30, 2015 21:32
Example of promoting a value to a type using higher ranked types, continuation passing and GADTs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Data.Proxy
import Data.Type.Equality