http://code.google.com/p/fsharp-typeclasses/ てきな型クラスを使おうとすると、コンパイラがNullReferenceExceptionを吐いて落ちることがある。 VS2010でもVS11betaでも再現する。
- 2つのライブラリプロジェクト(TypeClassLibとClientとする)を用意する
| 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() |
| // 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 |
| 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" |
| // 今の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; | |
| }; |
| // 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 |
http://code.google.com/p/fsharp-typeclasses/ てきな型クラスを使おうとすると、コンパイラがNullReferenceExceptionを吐いて落ちることがある。 VS2010でもVS11betaでも再現する。
| datatype 'a result = | |
| Pass | |
| | Failure of { Actual: 'a, Expected: 'a } | |
| ; | |
| fun test [] = [] | |
| | test (x::xs) = | |
| let | |
| val actual = (#Target x)() | |
| val expected = #Expected x |
| 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, |
| <?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 |