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 / gist:3915964
Created October 19, 2012 02:48
処理結果コードマジクソ
public class Hoge
{
// 処理結果コードを返す
public string Piyo(...) { ... }
public readonly int ResultA;
public readonly string ResultB;
}
var code = h.Piyo(...);
// ローカル変数のletは、C#のvarと同じものと思っておけば(とりあえずは)よい
// var x = 42;
let x = 42
// 関数定義のletは、C#で
// var f = new Func<int, string>(i => i.ToString());
// という書き方で、関数定義もできてしまう、と考える
let f (i: int) = i.ToString()
@bleis-tift
bleis-tift / gist:3774779
Created September 24, 2012 07:36
型拡張でオーバーロードすると式木が取れない
// fsiで
type Hoge() =
member this.Piyo(i: int) = "piyo1"
member this.Piyo(s: string) = "piyo2"
let f () =
<@ (fun (h: Hoge) -> h.Piyo(42)) @>;; // <- ここと、
type Hoge with
@bleis-tift
bleis-tift / gist:2969500
Created June 22, 2012 00:32 — forked from forki/gist:2964839
Static duck typing (F#2.0)
let inline speak (a: ^a) =
let x = (^a : (member Name: string) (a))
printfn "I'm %s" x
let y = (^a : (member talk: unit -> string) (a))
printfn "I say %s" y
//type Duck =
// { Name : string } // Name is not property in F# 2.0
//
// member x.talk() = "quackity quack"
@bleis-tift
bleis-tift / gist:2904624
Created June 10, 2012 09:26
JSXでカリーな無名関数書いたら死ねる
// 今のJSXだと何書いてるかわからん
var adder1 = function(x: int): function(: int): int {
return function(y: int): int { return x + y; };
};
// 俺の提案でも->で死ぬるが、
var adder2 = (x: int): (int) -> int -> (y: int): int -> x + y;
// 無理してsimple lambda使わなければ、それなりに読める
var adder3 = (x: int): (int) -> int -> {
return (y: int): int -> x + y;
};
@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
@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 / 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 / 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 / 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