Skip to content

Instantly share code, notes, and snippets.

View relrod's full-sized avatar

Rick Elrod relrod

View GitHub Profile
@chrisdone
chrisdone / 0-PHOAS-total-evaluator.hs
Last active March 24, 2024 16:55
Various lambda-calculus implementations
-- λ> eval (A (L (\(C i) -> C (i * 2))) (C 2))
-- 4
{-# LANGUAGE GADTs #-}
data E a where
C :: a -> E a
L :: (E a -> E b) -> E (a -> b)
A :: E (a -> b) -> E a -> E b
@rampion
rampion / SO25210743.hs
Last active August 29, 2015 14:05
Solution for [Bicategories in Haskell](http://stackoverflow.com/questions/25210743/bicategories-in-haskell) on StackOverflow
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
@rossdylan
rossdylan / fedmsg.hs
Created July 12, 2014 00:04
simple fedmsg haskell thingy
module Main where
import System.ZMQ
import Control.Monad (replicateM, forever)
import qualified Data.ByteString
import Text.Printf
type Topics = [String]
type MessageHandler = (Data.ByteString.ByteString -> IO ())
subscribeTopics :: SubsType a => Topics -> Socket a -> IO ()
@andrejbauer
andrejbauer / topology.v
Last active November 28, 2023 19:40
How to get started with point-set topology in Coq. This is not actually how one would do it, but it is an intuitive setup for a classical mathematician.
(* How do to topology in Coq if you are secretly an HOL fan.
We will not use type classes or canonical structures because they
count as "advanced" technology. But we will use notations.
*)
(* We think of subsets as propositional functions.
Thus, if [A] is a type [x : A] and [U] is a subset of [A],
[U x] means "[x] is an element of [U]".
*)
Definition P (A : Type) := A -> Prop.
@puffnfresh
puffnfresh / Monoid.v
Created April 24, 2014 15:08
Verified monoid in Coq.
Inductive bool : Type :=
| true : bool
| false : bool.
Class Monoid (A : Type) :=
{
empty : A ;
append : A -> A -> A ;
left_neutrality : forall x, append empty x = x ;
@puffnfresh
puffnfresh / AlaCarte.hs
Created April 1, 2014 22:46
Coproduct to combine algebras for a free monad interpreter.
module AlaCarte where
-- Control.Monad.Free
data Free f a = Free (f (Free f a)) | Pure a
instance Functor f => Monad (Free f) where
Pure a >>= f = f a
Free r >>= f = Free (fmap (>>= f) r)
return = Pure
@AndrasKovacs
AndrasKovacs / Mini2048.hs
Last active July 15, 2017 12:10
2048 game clone. Has identical mechanincs to "http://gabrielecirulli.github.io/2048/" as far as I can tell.
{-
Copyright (C) 2014 András Kovács
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOF
@relrod
relrod / gist:9505572
Last active August 29, 2015 13:57
Lens dependencies for Fedora
Unpackaged ghc-lens deps:
BuildRequires: ghc-bifunctors-devel #
BuildRequires: ghc-comonad-devel #
BuildRequires: ghc-contravariant-devel #1075598
BuildRequires: ghc-distributive-devel #1075605
BuildRequires: ghc-exceptions-devel #1075601
BuildRequires: ghc-profunctors-devel #
BuildRequires: ghc-reflection-devel #1076737
@darkf
darkf / lc.hs
Created March 5, 2014 01:58
Simply typed lambda calculus interpreter in Haskell
import Data.Maybe (fromJust)
data Type = IntTy
| ArrowTy Type Type
deriving (Show, Eq)
data Term = Const Int
| Var String
| Abs String Type Term
| App Term Term
@puffnfresh
puffnfresh / lenz-readme.md
Created February 18, 2014 01:25
Scala Lenz README

Scala Lenz

This library is a port of Haskell's lens. The goal is to provide functional lenses, isomorphisms, getters and setters.

Examples

Isomorphisms