Skip to content

Instantly share code, notes, and snippets.

View forki's full-sized avatar

Steffen Forkmann forki

View GitHub Profile
namespace CsharpMonads
{
using System.Collections.Generic;
using Xunit;
public static class DictionaryExtension
{
public static Maybe<S> TryFind<T, S>(this Dictionary<T, S> dict, T key)
{
if (dict.ContainsKey(key))
@forki
forki / HaskelDict
Created June 22, 2010 13:21
Sample for using the maybe monad in C#.
public static class MaybeConcat
{
public static Maybe<T> Concat<T>(this Maybe<T> source1, Func<Maybe<T>> source2F)
{
return source1.IsNone ? source2F() : source1;
}
}
public class HaskellLookupSample
{
public class EnumerableLookupSample
{
private static readonly Dictionary<string, string> FullNamesDb =
new Dictionary<string, string>
{
{ "Bill Gates", "billg@microsoft.com" },
{ "Bill Clinton", "bill@hope.ar.us" },
{ "Michael Jackson", "mj@wonderland.org" }
};
type OptionBuilder() =
member b.Delay(f) = f()
member b.Return(x) =
match x with
| None -> None
| Some r -> Some(r)
member b.Bind(p,rest) =
type OptionBuilder() =
member b.Delay(f) = f()
member b.Return(x) =
match x with
| None -> None
| Some r -> Some(r)
member b.Bind(p,rest) =
module Server
type StartParams =
{ TimeOut: int;
Url: string; }
let startServer serverName startParams =
printfn "%s %d" serverName startParams.TimeOut
using System;
namespace Aperea.iCalendar
{
public class Calendar
{
public void SetTime(DateTime dateTime)
{
}
using System;
namespace Aperea.iCalendar
{
public class Calendar
{
public void SetTime(DateTime dateTime)
{
}
@forki
forki / gist:730317
Created December 6, 2010 14:07
Sudoku solver
open System.Collections.Generic
type Box = int
type Sudoku = Box array array
let rows = id
let cols (sudoku:Sudoku) =
sudoku
|> Array.mapi (fun a row -> row |> Array.mapi (fun b cell -> sudoku.[b].[a]))
@forki
forki / gist:833568
Created February 18, 2011 11:42
.nuspec file for NaturalSpec
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<description>@description@</description>
<id>@project@</id>
<version>@build.number@</version>
<authors>@authors@</authors>
<owners>@authors@</owners>
<language>en-US</language>
<summary>@summary@</summary>