Skip to content

Instantly share code, notes, and snippets.

View axman6's full-sized avatar

Alex Mason axman6

View GitHub Profile
{-# LANGUAGE ConstraintKinds, DataKinds, PolyKinds, TypeFamilies,
TypeOperators, RankNTypes, TypeFamilies, UndecidableInstances #-}
import GHC.Prim (Constraint)
import Control.Exception -- (Exception, SomeException, catch, throw)
newtype Throws (es :: [k]) a = Throws (IO a)
type family Contains (e :: k) (es :: [k]) :: Constraint where
{-# LANGUAGE ConstraintKinds, DataKinds, PolyKinds, TypeFamilies,
TypeOperators, RankNTypes, TypeFamilies, UndecidableInstances #-}
import GHC.Prim (Constraint)
import Control.Exception -- (Exception, SomeException, catch, throw)
import Control.Monad (ap)
type family If (b :: Bool) :: Constraint where
@axman6
axman6 / Monad-constrained.hs
Last active August 29, 2015 14:07
Constrained Monads
{-# LANGUAGE ConstraintKinds, TypeFamilies #-}
{-# LANGUAGE RebindableSyntax #-}
-- {-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
import Data.Set (Set, unions, toList, singleton)
import qualified Data.Set as S
import GHC.Prim
@axman6
axman6 / Import double.sublime-snippet
Last active August 29, 2015 14:07
Haskell double import snippet
<snippet>
<!--
Produces imports of the form:
import qualified Data.Foo as F
import Data.Foo (Foo, fun)
Foo and F in as and includes sections are determined by the last
name in the module string: Foo -> F and Foo, Data.Foo -> F and Foo
-->
@axman6
axman6 / nlz.hs
Created December 23, 2014 04:39
log2 Word64 and count leading zeros
{-# LANGUAGE BangPatterns #-}
import Data.Bits
import Data.Word
nlz :: Word64 -> Int
nlz x = go x x 0 where
go !x !y !n
| x < 0 = n
| y == 0 = 64 - n
@axman6
axman6 / scavenge_large_srt_bitmap with ctz optimisation.c
Last active August 29, 2015 14:13
GHC scavenge_large_srt_bitmap possible optimisation
/* Similar to scavenge_large_bitmap(), but we don't write back the
* pointers we get back from evacuate().
*/
#define SPARSE_BITS 8
static void
scavenge_large_srt_bitmap( StgLargeSRT *large_srt )
{
nat i, j, size;
fft :: [[Integer]] -> [Integer] -> Integer -> Integer -> Integer -> Integer
fft as rho m mM sig pc = ... cooleyTukey bs (rhoMult m mM) (mM `div` mM) ...
where Ibs = zipWith (badMult m mM sig pc) pr as
pr = powersOfRho (m * 2) rho m mM sig pc
data Constants = C { mM :: Integer, sig :: Integer, pc :: Integer}
fft :: [[Integer]] -> [Integer] -> Integer -> Integer -> Integer -> Integer
fft as rho m mM sig pc = runReader fft' (Constants mM sig pc)
@axman6
axman6 / gist:1073412
Created July 9, 2011 07:08 — forked from o-sam-o/gist:1073350
Haskell Hack
import Data.Char
import Data.Maybe
import Data.List
import Data.Map hiding (map)
import Text.Printf
main :: IO ()
main = do
(src :: String) <- readFile "grades.txt" :: IO String
let pairs = map (\x -> split (words x)) ((lines src) :: [String]) :: [(String,Int)]
@axman6
axman6 / gist:1074170
Created July 10, 2011 02:17
Binary tree that allows lazy reading from disk (if used with bytestring-mmap)
data BTree a
= Null
| Leaf a
| Node a (BTree a) (BTree a)
deriving (Show)
-- makeTree :: [a] -> BTree a
-- makeTree xs =
instance Binary a => Binary (BTree a) where

Keybase proof

I hereby claim:

  • I am axman6 on github.
  • I am axman6 (https://keybase.io/axman6) on keybase.
  • I have a public key ASDRJGBz9LCxzTkIG-QeHrvptyisRGUkkQzePU6yy36uugo

To claim this, I am signing this object: