{ case 1 => "One" case 2 => "Two" case _ => "Many" }:Int=>String
{ case 1 => "One" case 2 => "Two" case _ => "Many" }:Int=>String
情報隠蔽とパターンマッチを巡って考えたことなど。 OCaml にはシグニチャという仕組みがあってオブジェクト指向言語でいうところのインターフェイスのようなものとして使われる。 例として次のようなスタックの実装を考えてみる。 module StackImpl = struct type 'a t = 'a list let empty = [] let push x s = x::s let pop (x::xs) = (x, xs) end モジュール StackImpl は単純にリストとしてスタックを定義している。 # let s = StackImpl.empty;; val s : 'a list = [] # let s = StackImpl.push 'a' s;; val s : char list = ['a'] # let s = StackImpl.push 'b' s
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く