Skip to content

Instantly share code, notes, and snippets.

View schar's full-sized avatar
💭
🦧

Simon Charlow schar

💭
🦧
View GitHub Profile
@ttesmer
ttesmer / AD.hs
Last active June 7, 2024 03:56
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@bond15
bond15 / FibHist.hs
Last active November 4, 2022 15:42
Fibonacci Histomorphism
module Fib where
import Control.Arrow((>>>),(&&&))
import Control.Comonad.Cofree
newtype Fix f = In { out :: (f (Fix f) ) }
data NatF a = Z | S a deriving Show
-- Peano natural numbers as the least fixed point of functor NatF
type Nat = Fix NatF
@duplode
duplode / Whereslift.hs
Last active June 23, 2019 22:55
"Where's lift?" -- Runnable examples from https://stackoverflow.com/a/56726855/2751851
#!/usr/bin/env cabal
{- cabal:
build-depends: base >= 4.12
, mtl
, distributive
-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@dylnb
dylnb / Paychecks.hs
Last active February 18, 2019 00:31
testing dependent currying
{-# LANGUAGE GADTs, FlexibleInstances #-}
module Paychecks where
type E = String
data Z
data S n
data Arity k where
@danidiaz
danidiaz / _FP reading lists.md
Last active May 23, 2024 04:02
assorted reading lists

A series of reading lists mostly related to functional programming.

@jtobin
jtobin / foo.hs
Created February 15, 2016 21:39
Independence and Applicativeness
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
import Control.Applicative.Free
import Control.Monad
import Control.Monad.Free
import Control.Monad.Primitive
import System.Random.MWC.Probability (Prob)
import qualified System.Random.MWC.Probability as MWC
@wenkokke
wenkokke / AB_grammar.hs
Last active January 24, 2024 14:51
AB grammars and extensible effects can do some fun things—depends on Eff1.hs found on <http://okmij.org/ftp/Haskell/extensible/>
{-# LANGUAGE TemplateHaskell, QuasiQuotes, FlexibleInstances, FlexibleContexts,
TypeFamilies, GADTs, TypeOperators, DataKinds, PolyKinds, RankNTypes,
KindSignatures, UndecidableInstances, StandaloneDeriving,
RecordWildCards, DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
module AB where
import Prelude hiding (lookup, lex)
import Control.Applicative ((<|>),empty)
import Data.Maybe (maybeToList)
@msullivan
msullivan / MicroKanren.hs
Created February 26, 2015 22:54
MicroKanren (μKanren) in Haskell
import Control.Monad
type Var = Integer
type Subst = [(Var, Term)]
type State = (Subst, Integer)
type Program = State -> KList State
data Term = Atom String | Pair Term Term | Var Var deriving Show
-- Apply a substitution to the top level of a term
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-- * Typed tagless-final interpreters for
-- * Linear Lambda Calculus
-- * de Bruijn indices
-- Linear lambda-calculus: each bound variable
-- is referenced exactly once.
tell application "Skim"
set theFile to the file of the front document
set outText to ""
set newLine to ASCII character 10
# Get the relevant bibliographic information for the front PDF in Skim
tell application "BibDesk"
repeat with currentPub in publications of front document
if linked file of currentPub is {} then
set bibFile to 0