Skip to content

Instantly share code, notes, and snippets.

@tonymorris
tonymorris / TypeClass.hs
Last active September 15, 2020 13:17
Type-class hierarchy
Moved to https://github.com/tonymorris/type-class
@xerxesb
xerxesb / gist:4654224
Last active December 11, 2015 20:18
First run at a solution to the Call Recording/Ordering kata
using System;
using System.Collections.Generic;
using System.Diagnostics;
using NUnit.Framework;
using Shouldly;
using System.Linq;
namespace MethodInfos
{
public class Formatter
@liammclennan
liammclennan / 1.3.ss
Created May 5, 2013 04:36
Sicp 1.1 exercises
(define (doit a b c)
(define descending (sort (list a b c) >))
(+ (square (car descending)) (square (car (cdr descending))))
)
{-# LANGUAGE OverloadedStrings #-}
import qualified Network.HTTP.Conduit as H
import Control.Exception
import Web.Scotty
import System.Environment
import System.IO
import System.Directory
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy.Char8 as BS
@mausch
mausch / gist:6774627
Created October 1, 2013 06:37
Applicative validation is simple.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
// As opposed to magic validation libraries that rely on reflection and attributes,
// applicative validation is pure, total, composable, type-safe, works with immutable types, and it's easy to implement.
public abstract class Result<T> {
private Result() { }
@tonymorris
tonymorris / PureIO.cs
Last active April 2, 2022 16:23
A demonstration of pure-functional I/O using the free monad in C#
using System;
namespace PureIO {
/*
C# does not have proper sum types. They must be emulated.
This data type is one of 4 possible values:
- WriteOut, being a pair of a string and A
- WriteErr, being a pair of a string and A
- readLine, being a function from string to A
@ColinScott
ColinScott / gist:9443227
Created March 9, 2014 05:22
Adding ExpectedObjects to NSubstitute
This adds a new Arg.ShouldMatch<T> method that uses expected objects to verify the received argument matches the expected object. For example the code below gives an error message of "ReceivedCallsException: Expected to receive exactly 1 call matching:
Blah(For Thing.Stuff, expected "Whatever2" but found "Whatever".
For Thing.OtherStuff, expected "abcd2" but found "abcd".
)
Actually received no matching calls.
Received 1 non-matching call (non-matching arguments indicated with '*' characters):
Blah(*Thing*)"
void Main()
{
#!/bin/sh
# Attempts to build a cabal binary package and symlink it in ~/.cabal/bin/
# Don't do this for binaries that rely on other assets! (such as pandoc)
# USE AT YOUR OWN RISK!
set -e
ws="[^a-zA-Z0-9\-\.]"
if [ "$#" -ne 1 ]
then
@bitemyapp
bitemyapp / gist:ac316a6eb666695ff7d2
Last active November 4, 2020 04:11
How I talk about Haskell when I want people to care about learning Haskell

Fire up ghci. Make the text real big. Always show the types for everything as you go!

Takes ~1 hour generally.

Note: if you object to "uncertainty" (evocative of data/value flow possibilities), consider wording like "simultaneously possible values". It's a reference to how the compiler won't know whether Maybe a is a Just a or a Nothing statically. Don't blather at me about dependent types; I know.

Alternate verbiage for uncertainty: product - simultaneous altogetherness, sum - simultaneous singlehood. Also consider what the category theoretic diagrams look like. Can be instructive.

Suggestions taken under advisement.

@shiftkey
shiftkey / explore.md
Last active July 27, 2022 13:24
WTF happened to my line endings?

This is a quick guide to debug potential line ending weirdness.

Note: I've thrown a lot of concepts in here around Git data structures without going into depth. If there's things that are unclear or you'd like some more details, just leave a comment and I'll either reply or expand on this post accordingly...

What sort of weirdness am I referring to? Consider this commit: https://github.com/dalefrancis88/Windsor/commit/e2543e5573781c7ded83166932c9c415feef11c0

While it looks like a very large commit, the contents of the file are unchanged. But the diffs are very intimidating.