Skip to content

Instantly share code, notes, and snippets.

View segfault.hs
import Foreign
main :: IO Int
main = peek nullPtr
View wat.c??
#include <stdio.h>
char X = 'a';
int main(int argc, char* argv[])
{
(void) argc;
(void) argv;
struct X {
View cabal.rst

The Cabal/Stack Disambiguation Guide

One of the most frequently asked Haskell beginner questions in recent years is:

"Stack or cabal?"

I will helpfully not answer this question. Instead I will hope to eliminate the confusion that many of the askers seem to have about the various different

View concrete-type-rant.rst

Why You Should Stop Saying "Concrete Type"!

TL;DR: There is no concrete (hah!) definition of "concrete type", different people are meaning different things by those words and assuming everyone else means the same thing.

A Quick Type Primer

@merijn
merijn / FizzBuzz.hs
Last active Jan 24, 2019
Generalised FizzBuzz
View FizzBuzz.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Monad (forM_)
import Data.Maybe (fromMaybe)
generalisedFizzBuzz
:: forall a f m
. (Foldable f, Semigroup m)
=> (a -> m) -> (a -> a -> Bool) -> f (a, m) -> a -> m
@merijn
merijn / Scraper.hs
Created Jul 9, 2015
Concurrent webscraper
View Scraper.hs
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent.Async
import Control.Concurrent.QSem
import Control.Monad
import Control.Monad.Catch
import Control.Monad.Trans
import Control.Monad.Reader
import Data.ByteString.Lazy (ByteString)
View DropAt.hs
dropAt :: Int -> [a] -> [a]
dropAt = go id
where
go :: ([b] -> [b]) -> Int -> [b] -> [b]
go f n [] = f []
go f 0 (x:xs) = f xs
go f n (x:xs) = go (f . (x:)) (n-1) xs
@merijn
merijn / Split.hs
Last active Jan 18, 2016
Efficient split in half
View Split.hs
splitInHalf :: [a] -> ([a], [a])
splitInHalf [] = ([], [])
splitInHalf xs = go id xs xs
where
go :: ([b] -> [b]) -> [b] -> [b] -> ([b], [b])
go f xs [] = (f [], xs)
go f xs [_] = (f [], xs)
go f (x:xs) (_:_:ys) = go (f . (x:)) xs ys
View examples.hs
let myMap = fix (\map' f list -> case list of [] -> []; (x:xs) -> f x : map' f xs) in myMap (+1) [1..]
View gist:0392ae239b9a091986ae
#include <stdio.h>
int main(int argc, char **argv)
{
int d = sizeof(0)["ABCDEFGHIJKLMNOPQRSTUWVXYZ"];
printf("%d\n", d);
return 0;
}