Skip to content

Instantly share code, notes, and snippets.

@pwm
pwm / MtlExample.hs
Last active July 13, 2020 16:58
Mtl example
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module MtlExample where
@pwm
pwm / NixOverlays.hs
Last active August 8, 2020 22:04
Nix Overlays in Haskell
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
module NixOverlays where
import Data.Foldable (foldl')
import Data.Function (fix)
import qualified Data.HashMap.Lazy as HMap
@pwm
pwm / Contributing.md
Created June 13, 2020 15:54 — forked from MarcDiethelm/Contributing.md
How to contribute to a project on Github

This text now lives at https://github.com/MarcDiethelm/contributing/blob/master/README.md. I turned it into a Github repo so you can, you know, contribute to it by making pull requests.


Contributing

If you want to contribute to a project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies and and their ecosystems and how to make constructive, helpful bug reports, feature requests and the noblest of all contributions: a good, clean pull request.

@pwm
pwm / JsonPatch.hs
Last active February 25, 2020 17:24
Json patch
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GADTs #-}
module Chaucer.UKTerrorism.JsonPatch where
import Build.Core.Prelude hiding (diff)
import Control.Lens
import Data.Aeson
import Data.Aeson.Diff hiding (Config)
import Data.Aeson.Diff.Generic
@pwm
pwm / JijoExample.hs
Created February 9, 2020 12:47
a Jijo Example
module JijoExample where
import Control.Category ((>>>))
import Data.Aeson
import Data.Aeson.Types
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Scientific (Scientific)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Lazy.Encoding as Text
@pwm
pwm / PTraverse.hs
Last active September 30, 2019 14:33
Parameterised Traversals
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ExistentialQuantification #-}
-- https://www.cs.ox.ac.uk/jeremy.gibbons/publications/dgp.pdf - 5.6
module PTraverse where
import Control.Monad.State.Strict
@pwm
pwm / NegatePos.hs
Last active October 1, 2019 12:20
Smart constructor vs. Generic Lens
module NegatePos where
import Control.Lens
import Data.Generics.Product
import Pos
negatePos :: Pos -> Pos
negatePos = position @1 %~ negate
@pwm
pwm / TDSL.hs
Last active October 1, 2019 12:20
Type level DSL
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module TDSL where
-- Our DSL
data Zero
data Succ a
@pwm
pwm / ParseFoo.hs
Last active July 30, 2019 16:43
Parse a substructure from json
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
module ParseFoo where
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Encoding as T
@pwm
pwm / Nat.hs
Last active July 1, 2019 11:09
Nat
{-# LANGUAGE InstanceSigs #-}
module Nat where
data Nat
= Zero
| Succ Nat
deriving (Eq, Ord, Show)
class AdditiveSemigroup a where