Skip to content

Instantly share code, notes, and snippets.

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!

import Data.Tree hiding (unfoldTreeM_BF, unfoldForestM_BF)
import Data.Traversable
import Prelude hiding (sequence)
import Control.Monad.Free
import Data.Functor.Identity
unfoldTreeM_BF :: Monad m => (b->m (a, [b])) -> b -> m (Tree a)
@treeowl
treeowl / monoidsolverthing
Last active August 29, 2015 14:20
Semigroup solver thing
module Mon
import Set
%default total
%access public
data MonBit a = MkMonBit a | MonZero
data Mon a = MkMon (Sem (MonBit a))
evalM' : MyMonoid a => Sem (MonBit a) -> a
@treeowl
treeowl / freemagma
Last active August 29, 2015 14:20
Binary leaf trees are free magmas
module Set
%default total
infixl 4 ~=
class Set c where
(~=) : (x,y:c) -> Type
rfl : {x:c} -> x ~= x
symm : {x,y:c} -> x ~= y -> y ~= x
@treeowl
treeowl / Magmas
Created May 8, 2015 00:44
Free magmas and semigroups
-- Construction of the free magma over an arbitrary type.
module Magma
import Set
%default total
%access public
infixl 6 <++>
class Set c => Magma c where
{-# LANGUAGE DeriveFunctor, BangPatterns #-}
module Queues.LazyMonadic where
import Data.Word
import Control.Applicative
import Control.Monad
data Result e a = Result
{ rval :: a
, rlen :: Word
, rremains :: [e]
@treeowl
treeowl / Ix.hs
Last active April 26, 2016 19:35
ix :: Applicative f => Int -> (a -> f a) -> Seq a -> f (Seq a)
ix i@(I# i') f (Seq xs)
| 0 <= i && i < size xs = Seq <$> ixTreeE (\_ (Elem a) -> Elem <$> f a) i' xs
| otherwise = pure (Seq xs)
unInt :: Int -> Int#
unInt (I# n) = n
ixTreeE :: Applicative f
=> (Int# -> Elem a -> f (Elem a)) -> Int# -> FingerTree (Elem a) -> f (FingerTree (Elem a))
@treeowl
treeowl / gist:73a5464a8345d5716208a70ab1e4c5a9
Last active March 29, 2017 20:43
Fast Applicative sorting
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE InstanceSigs #-}
{-# OPTIONS_GHC -Wall -fwarn-incomplete-uni-patterns #-}
module AS2 where
@treeowl
treeowl / BasicNat.hs
Last active December 13, 2023 15:12
Fast total sorting of arbitrary Traversable containers
{-# LANGUAGE DataKinds, TypeFamilies, TypeOperators, GADTs,
ScopedTypeVariables, TypeOperators #-}
-- | Type-level natural numbers and singletons, with proofs of
-- a few basic properties.
module BasicNat (
-- | Type-level natural numbers
Nat (..)
, type (+)
@treeowl
treeowl / SingMap.hs
Last active December 19, 2018 06:03
Singleton maps
{-# language TypeInType, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeOperators,
GADTs, UndecidableInstances, NoStarIsType, TemplateHaskell, InstanceSigs,
TypeSynonymInstances, FlexibleInstances, BangPatterns #-}
module SingMap (module SingMap, module P, module F) where
import GHC.TypeLits hiding (type (<=))
import Data.Type.Bool
import Data.Type.Equality
import Data.Singletons
import Data.Traversable