Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
module LensesAndFunctionalReferences where
import Data.Char (chr, ord, toUpper)
import Data.Functor.Const (Const(Const, getConst))
import Data.Functor.Contravariant (Contravariant(contramap))
import Data.Functor.Identity (Identity(Identity, runIdentity))
@bradparker
bradparker / NewtypeLists.hs
Created April 2, 2019 05:12
Newtype Lists
{-# LANGUAGE TupleSections #-}
newtype NonEmpty a = NonEmpty { getNonEmpty :: (a, List a) }
newtype List a = List { getList :: Maybe (NonEmpty a) }
nil :: List a
nil = List Nothing
cons :: a -> List a -> List a
cons a =
@bradparker
bradparker / default.nix
Created March 5, 2019 10:06
Minimal Miso default nix file
let
overlay = self: super:
{
haskell = super.haskell // {
packages = super.haskell.packages // {
ghcjs = super.haskell.packages.ghcjs.extend (hself: hsuper: {
# Doctest fails to build with a strange error.
doctest = null;
# These require doctest to run their tests.
@bradparker
bradparker / dev
Last active January 8, 2022 02:23
Little typer notes
#!/usr/bin/env bash
main () {
local filename="the-little-typer.rkt"
tmux \
new-window "nix-shell --run 'vim $filename'"\; \
split-window "nix-shell --run 'entr -c racket $filename <<< $filename'"\; \
select-layout even-horizontal\; \
split-window -v "nix-shell --run 'racket -i'"
@bradparker
bradparker / Comonad.hs
Last active February 9, 2019 04:05
Hrm
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveFunctor #-}
{-# OPTIONS_GHC -Wall #-}
-- $ nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [ pkgs.random ])"
-- $ runhaskell Comonad.hs
module Main where
@bradparker
bradparker / CommonmarkJSON.hs
Created January 29, 2019 09:48
Common mark json
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where
import CMarkGFM
( ListAttributes
, Node
, NodeType
@bradparker
bradparker / Mtl.hs
Created January 15, 2019 06:23
YAY MTL!!!
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Control.Monad
import Control.Monad.Trans.State (runState, runStateT)
import Control.Monad.Trans.Except (runExceptT, runExcept)
import Control.Monad.Error.Class
import Control.Monad.State.Class
@bradparker
bradparker / Hasql.hs
Last active December 16, 2019 16:29
Hasql
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Control.Monad (replicateM)
import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)
import Data.Foldable (foldl')
import Data.Functor.Contravariant (contramap)
@bradparker
bradparker / Opaleye.hs
Last active December 19, 2018 23:31
Opaleye-in'
{-# LANGUAGE Arrows #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
import Data.Bool (bool)
import Data.Text (Text)
import Control.Arrow (returnA)
@bradparker
bradparker / Balance.hs
Created December 5, 2018 23:17
Wrong answer ... but fun
data Balance =
Balance !Int
!Int
deriving (Eq, Show)
instance Semigroup Balance where
Balance a b <> Balance c d
| b <= c = Balance (a + c - b) d
| otherwise = Balance a (d + b - c)