Skip to content

Instantly share code, notes, and snippets.

namespace Samples.FSharp.TestTypeProvider
open System.Reflection
open Microsoft.FSharp.Core.CompilerServices
open Samples.FSharp.ProvidedTypes
open System.IO
open Microsoft.FSharp.Quotations
[<TypeProvider>]
type public TypeProvider1() as this =
@pthariensflame
pthariensflame / BracketInManyLanguages.md
Last active December 18, 2015 14:49
The signature of the `bracket` function in C#, Scala, Kotlin, Ceylon, Haskell, Agda, and Spellcode.

C#:

public static B Bracket<A, B>(Func<A> before, Action<A> after, Func<A, B> during);

Scala:

def bracket[A, B](before: =&gt; A, after: A =&gt; Unit)(during: A =&gt; B): B
@willurd
willurd / web-servers.md
Last active November 2, 2025 19:16
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@tonymorris
tonymorris / RefactoringPuzzle.scala
Created May 31, 2013 11:35
The following is an exercise in refactoring to remove code duplication. The implementation language is Scala. How would you solve it?
object RefactorPuzzle {
case class IntRdr[+A](read: Int => A) {
def map[B](f: A => B): IntRdr[B] =
IntRdr(f compose read)
def flatMap[B](f: A => IntRdr[B]): IntRdr[B] =
IntRdr(n => f(read(n)).read(n))
}
object IntRdr {
@dtchepak
dtchepak / surveyCsvExercise.md
Last active December 17, 2015 16:39
Survey to CSV coding exercise.

Survey CSV exercise

Background

We are surveying developers at a number of sites to find their favourite programming language. Each response from a site is stored in a type that contains the site name, and a map/dictionary of programming languages and the number of votes they received. In C# this could look something like this:

class SurveyResponse {
    public string Site;
 public Dictionary Results;
@tonymorris
tonymorris / MyOption.scala
Created May 20, 2013 22:12
Option semi-comonad ?
case class MyOption[A](o: Option[A]) {
def map[B](f: A => B): MyOption[B] =
MyOption(o map f)
def flatMap[B](f: A => MyOption[B]): MyOption[B] =
MyOption(o flatMap (f(_).o))
def coflatten: MyOption[MyOption[A]] =
MyOption(o match {
case None => None
@damncabbage
damncabbage / gist:5559408
Last active December 17, 2015 05:39
@jcoglan on CSS, DRY and composability.
@etorreborre
etorreborre / gist:5078824
Last active November 16, 2024 17:40
A good summary of Scala types from http://bit.ly/XjSVKw
class Outer {
class Inner
type Type
}
trait Trait
object Object extends Outer {
val inner = new Inner
}
class OuterP[A] {
class InnerP[B]
@pthariensflame
pthariensflame / IndexedState.md
Last active June 15, 2022 18:42
An introduction to the indexed state monad in Haskell, Scala, and C#.

The Indexed State Monad in Haskell, Scala, and C#

Have you ever had to write code that made a complex series of succesive modifications to a single piece of mutable state? (Almost certainly yes.)

Did you ever wish you could make the compiler tell you if a particular operation on the state was illegal at a given point in the modifications? (If you're a fan of static typing, probably yes.)

If that's the case, the indexed state monad can help!

Motivation

@danidiaz
danidiaz / gist:4967054
Created February 16, 2013 14:03
EnvT use case
import Data.Tree
import Control.Comonad
import Control.Comonad.Trans.Class
import Control.Comonad.Trans.Env
replusify:: MonadPlus m => [a] -> m a
replusify = msum . map return
class Treeish l where
children :: MonadPlus m => l -> m l