Skip to content

Instantly share code, notes, and snippets.

Avatar

Merijn Verstraaten merijn

View GitHub Profile
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;
}
@merijn
merijn / NoRankN.hs
Last active Dec 22, 2016
Haskell RankNType example
View NoRankN.hs
module RankN where
data Foo = Foo Int | Bar Double
mangle :: Num a => (a -> a) -> Foo -> Foo
mangle f (Foo i) = Foo (f i)
mangle f (Bar d) = Bar (f d)
{-
NoRankN.hs:6:25:
View ghc-hacking.rst
Authors: Merijn Verstraaten
Date: 2014/11/22

So You Want to Be a Super Cool GHC Hacker?

So you have a pet peeve/bug/feature request that you'd like to see added to GHC. You made sure there was a Trac_ ticket for it, but despite your patient waiting no one is solving your problem. Those selfish GHC hackers!

You can’t perform that action at this time.