これは、 @kmizu さんの「初学者向けの Scala Tips」を勝手に F# にポートした記事です。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FizzBuzzExtractor[T](f: T => Boolean){ | |
def unapply(t: T) = f(t) | |
} | |
val FizzBuzz = new FizzBuzzExtractor[Int](_ % 15 == 0) | |
object Fizz extends FizzBuzzExtractor[Int](_ % 3 == 0) | |
object Buzz extends FizzBuzzExtractor[Int](_ % 5 == 0) | |
object FizzBuzzRunner { | |
def run(num: Int) = num match { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Interface | |
type ICallable<'a, 'b> = | |
abstract member callback: 'a -> 'b | |
// concrete class | |
type Callable<'a, 'b>(f: 'a -> 'b) = | |
interface ICallable<'a, 'b> with | |
member self.callback x = f x | |
// computation builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Reflection.Assembly]::LoadFile('/path/to/MongoDB.Driver.dll') | |
[System.Reflection.Assembly]::LoadFile('/path/to/MongoDB.Bson.dll') | |
$client = New-Object MongoDB.Driver.MongoClient("mongodb://hostname") | |
$server = $client.GetServer() | |
$db = $server.GetDatabase("test") | |
$user = $db.GetCollection("User") | |
foreach($doc in $user.FindAll() { | |
[System.Console]::WriteLine($doc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Message = string * AsyncReplyChannel<string> | |
let agent = new MailboxProcessor<Message>(fun inbox -> | |
let rec loop count = | |
async { | |
System.Threading.Thread.Sleep(1000) // something busy | |
let! msg, replyChannel = inbox.Receive() | |
printfn "%s" msg | |
replyChannel.Reply(msg + msg) | |
return! loop (count + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FsCheck.Ext | |
module Test = | |
open System | |
open FsCheck | |
open FsCheck.Arb | |
type JapaneseChar = char | |
let japaneseChar (s: string) = |
- タイトル
Erlang ユーザーガイドから始めよう
- バージョン
6.2
- 原文
- 原文の著作権者
Ericsson AB.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_dict(this, other): | |
"""2つの dict の和を取る関数(キー重複は後勝ち) | |
@this ベースとなる dict オブジェクト | |
@other 追加される dict オブジェクト | |
@return 2つの dict を合成した dict | |
""" | |
result = this.copy() | |
for key in other: | |
result[key] = other[key] | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Adder implements Applyable { | |
@override | |
public int func(int a, int b) { | |
return a + b; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TVar -> TResult | |
interface Applyable<TVar, TResult> { | |
public abstract TResult apply(TVar variable); | |
} |
OlderNewer