Skip to content

Instantly share code, notes, and snippets.

@konn
konn / Data.Aeson.Generic.DerivingVia.hs
Last active December 7, 2020 21:06
Type-driven safe derivation of ToJSON and FromJSON, using DerivingVia in GHC 8.6 and some type-level hacks
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveGeneric, DerivingVia #-}
{-# LANGUAGE ExplicitNamespaces, FlexibleContexts, FlexibleInstances #-}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds, ScopedTypeVariables, StandaloneDeriving #-}
{-# LANGUAGE TypeApplications, TypeFamilies, TypeInType, TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module Data.Aeson.Generic.DerivingVia
( StrFun(..), Setting(..), SumEncoding'(..), DefaultOptions, WithOptions(..)
, -- Utility type synonyms to save ticks (') before promoted data constructors
@Icelandjack
Icelandjack / SystemF.hs
Last active November 27, 2018 02:00
System F
-- SYSTEM F
-- http://homepages.inf.ed.ac.uk/slindley/papers/embedding-f.pdf
--
-- Type-level lambdas
-- https://gist.github.com/AndrasKovacs/ac71371d0ca6e0995541e42cd3a3b0cf
{-# language TemplateHaskell, ScopedTypeVariables, RankNTypes,
TypeFamilies, UndecidableInstances, DeriveFunctor, GADTs,
TypeOperators, TypeApplications, AllowAmbiguousTypes,

MonadError via MonadCatch and MonadThrow

First, the code

newtype Exceptional e m a = Exceptional { deExceptional :: m a }
  deriving (Functor, Applicative, Monad)

instance (Exception e, MonadThrow m) => MonadError e (Exceptional e m) where
 throwError = Exceptional . throwM
@tel
tel / Lens.js
Created June 20, 2015 05:06
Really simple van Laarhoven lenses in Javascript
const IdModule = {
fmap: (fn) => (x) => fn(x),
}
const ConstModule = {
fmap: (fn) => (x) => x,
}
/**
@paf31
paf31 / W.lhs
Last active November 3, 2022 13:26
Algorithm W
## Principal type-schemes for functional programs
**Luis Damas and Robin Milner, POPL '82**
> module W where
> import Data.List
> import Data.Maybe
> import Data.Function
@AjayRamanathan
AjayRamanathan / GoG-Proposal.md
Last active February 16, 2017 15:48
Grammar of Graphics Gsoc Proposal

#Layered Grammar of Graphics

  • Ajay Ramanathan
  • [Diagrams][309]
  • Mentor: [Chris][223]

###Short description:

The project aim is to implement layered [Grammar of Graphics][303], in [Haskell][308] using [Diagrams][309] as backend. The core ideas is to start with the raw data and think about all the transformations, statistics, etc. that go into graphing it. With a good framework, this can help us see connections between different graphs and create new ones. You’ll realize that a pie chart is basically just a stacked bar chart plotted in polar coordinates, with bar height mapped to pie-slice angle… and that can get you thinking.

@davidgranstrom
davidgranstrom / ohs.md
Created October 9, 2012 22:33
ohs anteckningar

OpenHackSpace

GENERELLT

  • Fasta punkter/ämnen att diskutera
  • Hur går man på djupet utan att bli för specifik?
  • Ta fram exempel som är lätta att köra/testa
@pcapriotti
pcapriotti / gist:1761136
Created February 7, 2012 18:30
Composition of free monads
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
import Control.Monad
import Control.Monad.Free
class (Functor f, Functor g, Functor h) => Compose f g h | f g -> h where
compose :: f x -> g y -> Free h (Free f x, Free g y)
compose f g = return (liftF f, liftF g)
composeF :: Compose f g h => Free f x -> Free g x -> Free h x
@miikka
miikka / Simple.hs
Created August 24, 2010 19:07
Simple Haskell Twitter OAuth example
{-# LANGUAGE PackageImports #-}
{-
You need to register your Twitter application at <http://dev.twitter.com/>
to get the consumer key and secret needed for OAuth. When connecting to
Twitter for the first time, do this:
let consumer = Consumer "consumer key" "consumer secret"
token <- authenticate