Skip to content

Instantly share code, notes, and snippets.

View bitonic's full-sized avatar
🍥
bottomless pit

Francesco Mazzoli bitonic

🍥
bottomless pit
View GitHub Profile
{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | Run starting from "begin" and ending with "end", e.g.
--
-- @
-- ./MapReduce begin 10000 &
-- ./MapReduce segment 0 10001 '127.0.0.1' 10000 &
@bitonic
bitonic / A.hs
Created January 17, 2015 14:13
The dangers of incoherence
module A where
newtype MyInt = MyInt {unMyInt :: Int}
deriving (Show)
# Makefile tweaked for Ubuntu 14.04, install gnustep and gnustep-devel first.
HC = ghc
LIBDIR = $(shell $(HC) --print-libdir)
CFLAGS = -fobjc-arc -I$(LIBDIR)/include -I$(LIBDIR)/../../includes
HCFLAGS =
LDFLAGS = -package template-haskell -package language-c-quote -package language-c-inline -L/usr/lib/GNUstep/System/Library/Libraries/ -lgnustep-base -lobjc
OBJS = Main.o Main_objc.o
@bitonic
bitonic / gist:627fb9c1a5d494372d1d
Created April 14, 2015 01:19
loop video into v4l2loopback device
#include <gst/gst.h>
#include <glib.h>
typedef struct {
GMainLoop* loop;
GstElement* pipeline;
} LoopAndPipeline;
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
{
@bitonic
bitonic / crc32.hs
Last active August 29, 2015 14:20
import Control.Exception (evaluate)
import Control.Monad (forM_)
import Control.Monad (replicateM, forM)
import qualified Data.ByteString.Lazy as BS
import qualified Data.Digest.CRC32
import qualified Data.Digest.Pure.CRC32
import System.Environment (getArgs)
import qualified System.Random.MWC as MWC
import Data.Binary (encodeFile, decodeFile)
import Data.Word (Word32)
{-# LANGUAGE BangPatterns #-}
module OrdNub (ordNub) where
import Prelude hiding (null)
-- See Note: Order of constructors
data Set a = Bin {-# UNPACK #-} !Size !a !(Set a) !(Set a)
| Tip
type Size = Int

Macro types

I very often find myself wanting unboxed polymorphic types (e.g. types that contain UNPACKed type variables). I find it extremely frustrating that it's easier to write fast and generic code in C++ than in Haskell.

I'd like to submit to the mailing list a very rough proposal on how this could be achieved in a pretty straightforward way in GHC.

Keybase proof

I hereby claim:

  • I am bitonic on github.
  • I am bitonic (https://keybase.io/bitonic) on keybase.
  • I have a public key whose fingerprint is 81AE B4F4 45B7 79AD F92E 0872 F59F FEA3 BBE1 A8C8

To claim this, I am signing this object:

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
module Test where
import GHC.Generics
import Data.Kind
import qualified Data.Vector as V
import qualified Data.HashMap.Strict as HMS
import qualified Data.Map.Strict as Map
import Data.Hashable (Hashable)
type family WebApiType a :: *