これは、 @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
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 FSharp.Monad | |
type CoYoneda<'U> = | |
abstract Run: obj -> 'U | |
type CoYoneda<'F, 'A>(fi: 'F, k: CoYoneda<'A>) = class end | |
module CoYoneda = | |
let apply fa k = |
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
// 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
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
# -*- coding: utf-8 -*- | |
def class_extender(cls): | |
def __init__(self, value): | |
self.value = value | |
cls.__init__ = __init__ | |
return cls | |
@class_extender | |
class Hoge: |
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
let undefined _ = failwith "undefined" | |
let hoge (x : string) : int = undefined() |
金曜日、私は Heroku から Amazon Web Services(AWS) を直接使うように Soundslice を移行しました。私はこの変更ができてとても、そうとても嬉しくて、私がどうやったかということと、もし皆さんが同じような立場だったら何故それを検討すべきかということについて広く伝えたいと思います。
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
open System | |
//============================================ | |
// IOモナド | |
//============================================ | |
module IO = | |
type IO<'a> = IO of (unit -> 'a) | |
type IOBuilder() = | |
member this.Bind (IO x, f) = f (x()) |