Skip to content

Instantly share code, notes, and snippets.

@scott-fleischman
scott-fleischman / Bind.fs
Created March 4, 2016 00:56
F# for fun and profit - Computation Expressions - Bind exercise - http://fsharpforfunandprofit.com/posts/computation-expressions-bind/
// Exercises from http://fsharpforfunandprofit.com/posts/computation-expressions-bind/
// Part 1
let strToInt str =
match System.Int32.TryParse str with
| (false, _) -> None
| (true, x) -> Some x
type YourWorkflowBuilder() =
member this.Bind(x, f) = Option.bind f x
let preheatedOven = preheat oven 175<C>
let preparedPans = map (grease >> flour) pans
let flourMixture = whisk [ flour ; bakingSoda ; salt ]
creamUntil (all [ light ; fluffy ]) [ butter ; whiteSugar ; brownSugar ]
|> beatInOneAtATime eggs
|> mix bananas
|> addAlternately [ flourMixture ; buttermilk ]
|> stir (walnuts |> chop)
|> pourInto preparedPans
|> bake preheatedOven 30<min>
@scott-fleischman
scott-fleischman / Tutorial.agda
Last active February 24, 2016 16:48
Tutorial scratchpad for Dependently Typed Programming in Agda
module Tutorial where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
infix 3 _+_
_+_ : Nat -> Nat -> Nat
@scott-fleischman
scott-fleischman / PRL Reading Log.md
Created January 29, 2016 06:23
PRL Reading Log
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.2 for x86_64-apple-darwin):
Simplifier ticks exhausted
When trying UnfoldingDone $j_sdNBZ
To increase the limit, use -fsimpl-tick-factor=N (default 100)
If you need to do this, let GHC HQ know, and what factor you needed
To see detailed counts use -ddump-simpl-stats
Total ticks: 63261443
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
@scott-fleischman
scott-fleischman / Functional.cs
Created July 20, 2015 23:54
Gross C# functional stuff
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static Functional;
public static class Functional
{
public static Func<X, Z> Compose<X, Y, Z>(Func<Y, Z> g, Func<X, Y> f) => x => g(f(x));
@scott-fleischman
scott-fleischman / ResolveMaybe.agda
Last active August 29, 2015 14:24
Extract data from Maybe/Either with a proof
module ResolveMaybe where
data Maybe (A : Set) : Set where
none : Maybe A
some : A → Maybe A
data _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
@scott-fleischman
scott-fleischman / GreekScript3.agda
Created July 9, 2015 20:19
Yet another GreekScript approach in Agda
module GreekScript3 where
data Empty : Set where
Not : Set → Set
Not x = x → Empty
data _And_ (A B : Set) : Set where
_and_ : (a : A) → (b : B) → A And B
@scott-fleischman
scott-fleischman / lambda-calculus.md
Created July 7, 2015 19:47
Lambda Calculus Bibliography

Lambda Calculus

Church, Alonzo. The Calculi of Lambda Conversion. Princeton University Press, 1941.

Barendregt, Henk P. The Lambda Calculus. North Holland, revised edition, 1984.

Barendregt, Henk P. Functional programming and lambda calculus. In Jan van Leeuwen, editor, Handbook of Theoretical Computer Science, Volume B, chapter 7, pages 321–364. Elsevier / MIT Press, 1990.

Hindley, J. Roger and Jonathan P. Seldin. Introduction to Combinators andλ-Calculus, volume 1 of London Mathematical Society Student Texts. Cambridge University Press, 1986.

@scott-fleischman
scott-fleischman / gist:6d25bf77e2f0020d22c9
Created July 1, 2015 20:18
Untyped lambda calculus visualization ideas
  • AST editor
    • Variable entry/rename
    • Create fresh variable name
    • \ = lambda
    • space = apply
    • letters = variable
  • Show/hide unnecessary parentheses
  • Tree view?
  • Hover over variables shows binding
  • Maybe free variables of the same name or shadowed ones are highlighted in a different color?