Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
型付きWebフレームワークで遊んでみた
Search
kokuyouwind
July 14, 2014
Programming
1
1.9k
型付きWebフレームワークで遊んでみた
発表時間5分の社内LT大会で使用した資料です(実名・所属など一部改変)。
OCamlのWebフレームワークOcsigenを使ってみたので、その簡単な紹介となっています。
kokuyouwind
July 14, 2014
Tweet
Share
More Decks by kokuyouwind
See All by kokuyouwind
Let's use LLMs from Ruby 〜 Refine RBS types using LLM 〜
kokuyouwind
0
7.2k
APMをちゃんと使おうとしたら、いつのまにか独自gemを作っていた話
kokuyouwind
0
820
RBS meets LLMs - Type inference using LLM
kokuyouwind
0
870
オンラインボードゲームを作りたい人生だった
kokuyouwind
0
560
1年間本番運用してわかった、スタートアップこそAWS Copilot CLIを使うべきNつの理由
kokuyouwind
2
11k
なるべく楽したいAWSセキュリティ
kokuyouwind
1
80
Railsパフォーマンス・チューニング入門
kokuyouwind
0
330
Rubyパターンマッチに闇の力が備わり最強に見える
kokuyouwind
0
130
Slackワークフロー活用術
kokuyouwind
0
120
Other Decks in Programming
See All in Programming
はじめてのMaterial3 Expressive
ym223
2
250
Putting The Genie in the Bottle - A Crash Course on running LLMs on Android
iurysza
0
140
Cache Me If You Can
ryunen344
2
640
MCPでVibe Working。そして、結局はContext Eng(略)/ Working with Vibe on MCP And Context Eng
rkaga
5
2.2k
1から理解するWeb Push
dora1998
7
1.8k
Namespace and Its Future
tagomoris
6
700
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
110
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
490
Swift Updates - Learn Languages 2025
koher
2
470
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
0
400
Navigation 2 を 3 に移行する(予定)ためにやったこと
yokomii
0
130
🔨 小さなビルドシステムを作る
momeemt
3
670
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Facilitating Awesome Meetings
lara
55
6.5k
A Tale of Four Properties
chriscoyier
160
23k
For a Future-Friendly Web
brad_frost
180
9.9k
How to train your dragon (web standard)
notwaldorf
96
6.2k
The Pragmatic Product Professional
lauravandoore
36
6.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Transcript
型付きWebフレームワークで 遊んでみた @kokuyouwind
$ whoami • Web開発 3年目(PHP Only) • Twitter : @kokuyouwind
• ブログ : blog.kokuyouwind.com • ニコニコミュニティ : co1347624 • ポーカー好き このアイコンの人→
先週のハッカソン
テーマ:出会い
出会い → 協調作業
協調作業 → 一緒にお絵かき
お絵かきアプリだ!
デモ http://draw.kokuyouwind.com/
screenshot
普通じゃね?
面白い所: HTMLもJavaScriptも 書いてない!
Haml? TypeScript?
いえいえ
全てOCamlです!
Code on Github https://github.com/kokuyouwind/ocsigen-tutorial ロジック部分は全てOcamlコード graffiti.eliomは150行弱
謝罪
さっきのデモは チュートリアルの丸写しです 正直すまんかった
Ocsigen http://ocsigen.org/
基本記法 {shared{ type message = string }} {client{ let _
= Eliom_lib.alert "Hello!" }} let main_service = (* ... *) 共通コード クライアントコード サーバーコード
サービス定義 let main_service = Eliom_registration.Html5.register_service ~path:[“hello"] ~get_params:Eliom_parameter.unit (fun () ()
-> Lwt.return (html (head (title (pcdata “hello")) []) (body [h1 [pcdata “hello, world!"]]))) Html型の値を生成
サービス定義 let main_service = Eliom_registration.Html5.register_service ~path:["graff"] ~get_params:Eliom_parameter.unit (fun () ()
-> Lwt.return (html (head (title (pcdata "Page title")) []) (body [ul [pcdata "Graffiti"]]))) ↑コンパイル時に型エラー (ulの子要素がliじゃない)
サーバー変数埋め込み let message = “hello” {client{ let _ = Eliom_lib.alert
“%s” %message }} ↑ %hogeでサーバー側の 変数を参照
サーバー変数埋め込み let message = 0 {client{ let _ = Eliom_lib.alert
“%s” %message }} ↑ Stringじゃないので エラーになる
サーバー変数埋め込み let message = 0 {client{ let _ = Eliom_lib.alert
“%s” (string_of_int %message) }} ↑ これならオーケー
他にも… • Bus, React – イベントをやりとりする – 前者がEvent Driven, 後者がReactive
– 型が合わないとコンパイル時にエラー • Ajaxでのjsonとかの呼び出し – service定義を参照してurlを生成 – 型が合わないとコンパイル時にエラー
まとめ • Ocsigenだと全部Ocamlで書ける • コンパイル時点で型起因のバグは弾く • コードが割と短くなる • 学習コストは結構高い •
名古屋こわい • ことりちゃんかわいい http://tkotori.github.io/
終わり from @mzp
以下予備スライド
Ocsigenプロジェクト • OcsigenServer : Webサーバ • Eliom : Webフレームワーク •
Js_of_ocaml : JSコンパイラ • Lwt : 並列計算ライブラリ • 他色々 – http://ocsigen.org/overview/framework
ページサイズ • HTML : 3.39KB – 通信用の識別子とかが埋め込まれている • JavaScript :
282.39KB – OCamlバイトコード => JavaScriptコード – 直接読むのは多分辛い – 実行はかなり高速らしい • VM実行OCamlよりも速い場合があるとのこと
ことりちゃん? • 高階ことり • モナドの薄い本のイメージキャラクター – @dico_lequeさんの本(予定) – @bleisさんと@mzpさんの差し金 •
ことりちゃん可愛い • http://tkotori.github.io/
参考 • Ocsigenプロジェクトページ – http://ocsigen.org/ • OCamlで構築するモダンWeb – http://proofcafe.org/~keigoi/pplss2012- ocaml.pdf
• OCamlで作ったWebアプリをHerokuで 動かす方法(2) – http://mzp.hatenablog.com/entry/2013/06 /08/003029