Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
@carymrobbins
carymrobbins / TraceStack.hs
Last active November 1, 2019 19:15
Dumping stack traces in Haskell with GHC
import qualified Debug.Trace as DEBUG
import GHC.Stack
myTraceStack :: (HasCallStack) => String -> a -> a
myTraceStack msg = DEBUG.trace (msg <> "\n" <> prettyCallStack callStack)
-- We could define 'myTraceStackM' in terms of 'myTraceStack' but that would
-- include 'myTraceStackM' in the call stack. We could freeze the call stack,
-- but it's fairly simple to just redefine it instead.
myTraceStackM :: (Applicative m, HasCallStack) => String -> m ()
@gelisam
gelisam / FunDay.hs
Last active May 12, 2024 06:20
a concrete use for FunDay, the right-adjoint of Day
-- A concrete use case for the type which is to '(->)' as 'Day' is to '(,)'.
-- I call it "FunDay", but I don't know what its proper name is. I've been
-- trying to find a use for 'FunDay', and I think I've found a pretty neat one.
{-# LANGUAGE FlexibleContexts, FlexibleInstances, PolyKinds, RankNTypes, TypeSynonymInstances #-}
module Main where
import Test.DocTest
import Control.Monad.Except
import Control.Monad.Reader
@YoEight
YoEight / Main.hs
Last active September 27, 2019 06:32
eventstore client showdown
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NumericUnderscores #-}
module Main where
import Control.Monad
import Database.EventStore
import qualified Data.Text as Text
import Data.Aeson
@carymrobbins
carymrobbins / tc.cpp
Last active September 26, 2019 22:22
An example of implementing type classes in C++.
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <template <class, class...> class f>
struct functor {
template<typename a, typename b>
@kosmikus
kosmikus / Tutorial.hs
Last active May 1, 2020 23:59
Preliminary rewrite of Gabriel's lens tutorial to use `optics` instead of `lens`
{-| This @lens@ tutorial targets Haskell beginners and assumes only basic
familiarity with Haskell. By the end of this tutorial you should:
* understand what problems the @lens@ library solves,
* know when it is appropriate to use the @lens@ library,
* be proficient in the most common @lens@ idioms,
* understand the drawbacks of using lenses, and:
@cgibbard
cgibbard / MonadState.hs
Created September 2, 2019 05:04
How MonadState could potentially look, using DefaultSignatures and type equality constraints.
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Monad.Trans.Class
import qualified Control.Monad.Trans.State as State
import Control.Monad.Trans.Identity (IdentityT)
import Control.Monad.Trans.Reader (ReaderT)
set directory=~/.vim/backup
set backupdir=~/.vim/backup " keep swap files here
filetype off " required
call plug#begin('~/.local/share/nvim/plugged') " you need to create this directory first (or change it)
Plug 'vim-airline/vim-airline' " bottom status bar
Plug 'vim-airline/vim-airline-themes'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " fuzzy finder conf
Plug 'junegunn/fzf.vim' " fuzzy finder
@Shimuuar
Shimuuar / overload.hs
Created August 13, 2019 16:58
Override data types in instance
-- This is an approach to refine ability to selectively override
-- instances when deriving using deriving via method. Idea was first
-- presented here:
--
-- http://caryrobbins.com/dev/overriding-type-class-instances/
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
@paf31
paf31 / ToPursTyConPoly.hs
Last active April 8, 2020 07:08
ToPursTyConPoly
{-# language TypeInType #-}
-- | Types which have PureScript equivalents
class ToPursTyCon a where
toPursTyCon :: Tagged a PursTypeConstructor
-- | The default instance uses 'G.Generic' and pattern matches on the
-- type's representation to create a PureScript type.
default toPursTyCon :: (G.Generic a, GenericToPursTyCon (G.Rep a)) => Tagged a PursTypeConstructor
toPursTyCon = retag $ genericToPursTyConWith @(G.Rep a) defaultPursTypeOptions
@eborden
eborden / stack-ghcid.sh
Last active May 16, 2019 14:43
Run ghcid in a monorepo via stack
project=$(basename "$(pwd)")
# build dependencies
build_deps="stack build $project --fast --pedantic --dependencies-only --interleaved-output"
# restart on changes in other packages
restarts=$(find ../. -maxdepth 1 -type d \
-not -name "$project" \
-not -name .stack-work \
-not -name . \