Skip to content

Instantly share code, notes, and snippets.

View bleis-tift's full-sized avatar

bleis-tift bleis-tift

View GitHub Profile
@bleis-tift
bleis-tift / Patterns.fs
Created January 29, 2012 18:13
YAML(のサブセット)のパーサを書く試み
module Patterns
open Microsoft.FSharp.Reflection
let (|PrimitiveType|ListType|RecordType|) t =
if t = typeof<int> || t = typeof<string> then
PrimitiveType
else if FSharpType.IsRecord t then
RecordType t
else if t.GetGenericTypeDefinition() = typedefof<list<_>> then
@bleis-tift
bleis-tift / git-start
Created February 13, 2012 09:15
空コミットを最初のコミットとして作るコマンド(git initの代わり)
#!/bin/sh
msg=${1:-"first commit"}
git init
tree_hash=$(git write-tree)
commit_hash=$(echo -n "$msg" | git commit-tree $tree_hash)
echo $commit_hash > .git/refs/heads/master
using NUnit.Framework;
[TestFixture]
public class Sample : TestUtil
{
[TestCaseSource("TestCases")]
public void Test(int i, string expected)
{
Assert.That(i.ToString(), Is.EqualTo(expected));
}
sig System {
slist: some SSeat,
alist: some ASeat,
reserved: set slist + alist
}
abstract sig Seat {}
sig ASeat extends Seat {}
sig SSeat extends Seat {}
enum SeatType { A, S }
@bleis-tift
bleis-tift / C:\MinGW\var\lib\mingw-get\data\profile.xml
Created April 22, 2012 14:17
MinGW環境にSML#を入れる際のxmlの例
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<profile project="MinGW" application="mingw-get">
<repository uri="http://www.pllab.riec.tohoku.ac.jp/smlsharp/download/mingw32/%F.xml.lzma">
<package-list catalogue="smlsharp-package-list" />
</repository>
<!--
$Id: profile.xml,v 1.4 2010/08/24 20:02:10 keithmarshall Exp $
Written by Keith Marshall <[email protected]>
Copyright (C) 2009, 2010, MinGW Project
@bleis-tift
bleis-tift / error
Created April 22, 2012 16:01
SML#でCのlocaltimeをつかおうと思ったら出たエラー
val f = _import "localtime": int array -> time;の場合
(interactive):31.51-31.54 Error:
(type inference 003) not an interoperable type: {day: int,
dst: int,
hour: int,
min: int,
mon: int,
sec: int,
wday: int,
@bleis-tift
bleis-tift / ssunit.sml
Created April 28, 2012 05:02
SML#用の小さいテスティングフレームワーク
datatype 'a result =
Pass
| Failure of { Actual: 'a, Expected: 'a }
;
fun test [] = []
| test (x::xs) =
let
val actual = (#Target x)()
val expected = #Expected x
@bleis-tift
bleis-tift / gist:2642085
Created May 9, 2012 05:25
fsharp-typeclasses的な型クラスを使おうとするとコンパイラが落ちるバグの再現手順

バグ再現手順

http://code.google.com/p/fsharp-typeclasses/ てきな型クラスを使おうとすると、コンパイラがNullReferenceExceptionを吐いて落ちることがある。 VS2010でもVS11betaでも再現する。

手順

  1. 2つのライブラリプロジェクト(TypeClassLibとClientとする)を用意する
@bleis-tift
bleis-tift / ActivePatterns.fs
Created May 10, 2012 07:08
Active Pattern, Extractor, View Pattern
// F#
type Hoge = A of int | B of int | C of int
let (|AllHoge|) (A x | B x | C x) = AllHoge x
let f (AllHoge x) = x * 10
let xs = [A 1; B 2; C 3] |> List.map f