Skip to content

Instantly share code, notes, and snippets.

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

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

import Foreign
main :: IO Int
main = peek nullPtr
@merijn
merijn / wat.c??
Created February 26, 2021 10:13
C vs C++
#include <stdio.h>
char X = 'a';
int main(int argc, char* argv[])
{
(void) argc;
(void) argv;
struct X {
@merijn
merijn / MyState.hs
Last active January 15, 2021 19:20
MyState homework
data MyState s a = MyState (s -> (a, s))
get :: MyState s s
get = undefined
put :: s -> MyState s ()
put = undefined
modify :: (s -> s) -> MyState s ()
modify = undefined
#include <stdio.h>
int main(int argc, char **argv)
{
int d = sizeof(0)["ABCDEFGHIJKLMNOPQRSTUWVXYZ"];
printf("%d\n", d);
return 0;
}
@merijn
merijn / FizzBuzz.hs
Last active January 24, 2019 08:57
Generalised FizzBuzz
{-# 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 / gist:6130082
Last active January 2, 2019 10:07
Type family that disallows certain types for type variables.
{-# LANGUAGE ConstraintKinds, DataKinds, PolyKinds, TypeFamilies, TypeOperators #-}
import GHC.Exts (Constraint)
type family Restrict (a :: k) (as :: [k]) :: Constraint where
Restrict a (a ': as) = ("Error!" ~ "Tried to apply a restricted type!")
Restrict x (a ': as) = Restrict x as
Restrict x '[] = ()
foo :: Restrict a [(), Int] => a -> a
@merijn
merijn / gist:39dc86e345e87276c523
Last active January 2, 2019 10:07
Index list in haskell
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import GHC.Prim (Constraint)
data Nat = Succ Nat | Zero
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module HList where
import Prelude hiding (head, tail, zip)