{{ message }}

Instantly share code, notes, and snippets.

# Merijn Verstraaten merijn

Created Mar 5, 2021
View segfault.hs
 import Foreign main :: IO Int main = peek nullPtr
Created Feb 26, 2021
C vs C++
View wat.c??
 #include char X = 'a'; int main(int argc, char* argv[]) { (void) argc; (void) argv; struct X {
Last active Nov 7, 2020
View cabal.rst

# The Cabal/Stack Disambiguation Guide

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

"Stack or cabal?"

Last active Nov 15, 2020
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

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
Created Jul 9, 2015
Concurrent webscraper
View Scraper.hs
Created Jun 12, 2015
dropAt
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
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
Created May 3, 2015
Small examples
View examples.hs
 let myMap = fix (\map' f list -> case list of [] -> []; (x:xs) -> f x : map' f xs) in myMap (+1) [1..]
Created Feb 9, 2015
C popquiz
View gist:0392ae239b9a091986ae
 #include int main(int argc, char **argv) { int d = sizeof(0)["ABCDEFGHIJKLMNOPQRSTUWVXYZ"]; printf("%d\n", d); return 0; }