SlideShare a Scribd company logo
Non-Imperative Functional Programming
          序章: 要求駆動I/O

             2012-04-22

               山下伸夫
          nobsun@sampou.org
IO は命令書だ

main :: IO ()
main = do input    <- openFile "i" ReadMode
          contents <- hGetContents input
          hClose input
          output    <- openFile "o" WriteMode
          hPutStr output contents
          hClose output
          return ()
すぐやらなくてもいいLazyな命令
      書いちゃだめでしょ!

main :: IO ()
main = do input    <- openFile "i" ReadMode
          contents <- hGetContents input
          hClose input
          output    <- openFile "o" WriteMode
          hPutStr output contents
          hClose output
          return ()
命令書と実行結果
main :: IO ()
main = do line1 <-   getLine
          line2 <-   getLine
          putStrLn   line2
          putStrLn   line1
 ghci> :main
 world!↓
 Hello,↓
 Hello,
 world!
Lazyな命令があると?
main :: IO ()
main = do line1 <- lazy getLine
          line2 <- lazy getLine
          putStrLn line2
          putStrLn line1
          return ()
 ghci> :main

                    ?
Eagerな文脈にLazyな要素
main :: IO ()
main = do line1 <- lazy getLine
          line2 <- lazy getLine
          putStrLn line2
          putStrLn line1
          return ()
 ghci> :main
 world!↓
 world!
 Hello,↓
 Hello,
Eagerな文脈にLazyな要素
                                    !
main :: IO ()
main = do line1 <- lazy getLine    険
          line2 <- lazy getLine
          putStrLn line2          危
                な
          putStrLn line1

               る
          return ()
 ghci> :main
 world!↓
              ぜ
 world!
 Hello,↓
 Hello,
             ま
全部Lazyにしてしまえ!
main :: IO ()
main = do line1 <- lazy getLine
          line2 <- lazy getLine
          lazy (putStrLn line2)
          lazy (putStrLn line1)
          return ()
 ghci> :main


                  ?
Lazy = 要求駆動
main :: IO ()
main = do line1 <- lazy getLine
          line2 <- lazy getLine
          lazy (putStrLn line2)
                                ね
          lazy (putStrLn line1)
          return ()            だ
 ghci> :main                  然
 ghci>
                 当
                。
               ま
要求駆動I/O

main :: IO ()
main = do
  line1 <- lazy getLine
  line2 <- lazy getLine
  prn2 <- lazy (putStrLn line2)
  prn1 <- lazy (putStrLn line1)
  return $! sequencing [force line1
                        ,force line2
                        ,prn2
                        ,prn1]
要求駆動I/O
                          ス
                         ー !
                       ォ え
force :: a -> ()
force !x = ()         フ 使
                       を
sequencing :: [()] -> ()
sequencing sq = case dropWhile (()==) sq of
                  [] -> ()
IO は命令書だ

main :: IO ()
main = do
  input    <- lazy $ openFile "i" ReadMode
  icloseR <- lazy $ hClose input
  output   <- lazy $ openFile "o" WriteMode
  ocloseR <- lazy $ hClose output
  contents <- hGetContents input
  printR   <- lazy $ hPutStr output contents
  return $! sequencing
          $ [printR,icloseR,ocloseR]
ああ IO ()

main :: IO ()
main = do
  input    <- lazy $ openFile "i" ReadMode
  icloseR <- lazy $ hClose input
  output   <- lazy $ openFile "o" WriteMode
  ocloseR <- lazy $ hClose output
  contents <- hGetContents input
  printR   <- lazy $ hPutStr output contents
  return $! sequencing
          $ [printR,icloseR,ocloseR]
ああ IO ()



型はプログラムの
仕様じゃなかった
対話:: a :-> b としてのI/O

type a :-> b = OI a -> b

mainR :: a :-> ()
runI :: (a :-> b) -> IO b

main = runI mainR
oi package


実装についてはオイオイ
    to be continued

More Related Content

What's hot

Rakudo
RakudoRakudo
Rakudo
awwaiid
 
PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12
Kazuki KOMORI
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
Yusuke Kita
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
Noritada Shimizu
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
Lorenz Cuno Klopfenstein
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
tatsunori ishikawa
 
Biicode OpenExpoDay
Biicode OpenExpoDayBiicode OpenExpoDay
Biicode OpenExpoDayfcofdezc
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
Simon Proctor
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
Vibrant Technologies & Computers
 
Everyday's JS
Everyday's JSEveryday's JS
Everyday's JS
Adib Mehedi
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Yandex
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
Nattawut Phetmak
 
Getting Rest With Webmachine
Getting Rest With WebmachineGetting Rest With Webmachine
Getting Rest With Webmachine
kevsmith
 
3分くらいで分かるassert()
3分くらいで分かるassert()3分くらいで分かるassert()
3分くらいで分かるassert()
Ippei Ogiwara
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断nishio
 
Clojure + MongoDB on Heroku
Clojure + MongoDB on HerokuClojure + MongoDB on Heroku
Clojure + MongoDB on Heroku
Naoyuki Kakuda
 
String C# - Lec10 (Workshop on C# Programming: Learn to Build)
String C# - Lec10 (Workshop on C# Programming: Learn to Build)String C# - Lec10 (Workshop on C# Programming: Learn to Build)
String C# - Lec10 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
OXUS 20
 

What's hot (20)

Rakudo
RakudoRakudo
Rakudo
 
PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
 
Biicode OpenExpoDay
Biicode OpenExpoDayBiicode OpenExpoDay
Biicode OpenExpoDay
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
 
Shell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbaiShell and perl scripting classes in mumbai
Shell and perl scripting classes in mumbai
 
Everyday's JS
Everyday's JSEveryday's JS
Everyday's JS
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
 
Getting Rest With Webmachine
Getting Rest With WebmachineGetting Rest With Webmachine
Getting Rest With Webmachine
 
3分くらいで分かるassert()
3分くらいで分かるassert()3分くらいで分かるassert()
3分くらいで分かるassert()
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Clojure + MongoDB on Heroku
Clojure + MongoDB on HerokuClojure + MongoDB on Heroku
Clojure + MongoDB on Heroku
 
String C# - Lec10 (Workshop on C# Programming: Learn to Build)
String C# - Lec10 (Workshop on C# Programming: Learn to Build)String C# - Lec10 (Workshop on C# Programming: Learn to Build)
String C# - Lec10 (Workshop on C# Programming: Learn to Build)
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 

Viewers also liked

Social Networks
Social NetworksSocial Networks
Social Networks
cassmartin01
 
Fisling
FislingFisling
FislingSri P
 
digitális lábnyom 1
digitális lábnyom 1digitális lábnyom 1
digitális lábnyom 1denesabel
 
Other corporate profile
Other corporate profileOther corporate profile
Other corporate profile
prokopiosA
 
Gerlee tungaa
Gerlee tungaaGerlee tungaa
Gerlee tungaa
gerlee_7536
 
The biofeedback mouse
The biofeedback mouseThe biofeedback mouse
The biofeedback mouseprokopiosA
 
Gerlee tungaaaaaa
Gerlee tungaaaaaaGerlee tungaaaaaa
Gerlee tungaaaaaa
gerlee_7536
 
Gerlee tungaa
Gerlee tungaaGerlee tungaa
Gerlee tungaa
gerlee_7536
 
Nutritional skincare
Nutritional skincareNutritional skincare
Nutritional skincareSkintritious
 

Viewers also liked (17)

El agua es una riqueza
El agua es una riquezaEl agua es una riqueza
El agua es una riqueza
 
Social Networks
Social NetworksSocial Networks
Social Networks
 
Fisling
FislingFisling
Fisling
 
digitális lábnyom 1
digitális lábnyom 1digitális lábnyom 1
digitális lábnyom 1
 
Other corporate profile
Other corporate profileOther corporate profile
Other corporate profile
 
Gerlee tungaa
Gerlee tungaaGerlee tungaa
Gerlee tungaa
 
The biofeedback mouse
The biofeedback mouseThe biofeedback mouse
The biofeedback mouse
 
Gerlee tungaaaaaa
Gerlee tungaaaaaaGerlee tungaaaaaa
Gerlee tungaaaaaa
 
Gerlee tungaa
Gerlee tungaaGerlee tungaa
Gerlee tungaa
 
00 introduction
00   introduction00   introduction
00 introduction
 
Susses criteria
Susses criteriaSusses criteria
Susses criteria
 
2share2
2share22share2
2share2
 
Cbl group 3
Cbl group 3Cbl group 3
Cbl group 3
 
Nutritional skincare
Nutritional skincareNutritional skincare
Nutritional skincare
 
Cbl group 3
Cbl group 3Cbl group 3
Cbl group 3
 
Manduuhai
ManduuhaiManduuhai
Manduuhai
 
Manduuhai
ManduuhaiManduuhai
Manduuhai
 

Similar to ああLazy io

"Lego Programming" with Lorzy
"Lego Programming" with Lorzy"Lego Programming" with Lorzy
"Lego Programming" with Lorzyclkao
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in Scala
Wiem Zine Elabidine
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Philip Schwarz
 
Future vs. Monix Task
Future vs. Monix TaskFuture vs. Monix Task
Future vs. Monix Task
Hermann Hueck
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentials
Alexander Granin
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
Hiromi Ishii
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
Nova Patch
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理maruyama097
 
Haskell Jumpstart
Haskell JumpstartHaskell Jumpstart
Haskell Jumpstart
David Vollbracht
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
bob_is_strange
 
Kotlin Coroutines - the new async
Kotlin Coroutines - the new asyncKotlin Coroutines - the new async
Kotlin Coroutines - the new async
Bartłomiej Osmałek
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
Gyu-sun Youm
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
Gyu-sun Youm
 
6. processes and threads
6. processes and threads6. processes and threads
6. processes and threads
Marian Marinov
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
Dierk König
 
Programming simple games with a raspberry pi and
Programming simple games with a raspberry pi andProgramming simple games with a raspberry pi and
Programming simple games with a raspberry pi and
Kellyn Pot'Vin-Gorman
 

Similar to ああLazy io (18)

05. haskell streaming io
05. haskell streaming io05. haskell streaming io
05. haskell streaming io
 
"Lego Programming" with Lorzy
"Lego Programming" with Lorzy"Lego Programming" with Lorzy
"Lego Programming" with Lorzy
 
ZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in ScalaZIO: Powerful and Principled Functional Programming in Scala
ZIO: Powerful and Principled Functional Programming in Scala
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Future vs. Monix Task
Future vs. Monix TaskFuture vs. Monix Task
Future vs. Monix Task
 
Transition graph using free monads and existentials
Transition graph using free monads and existentialsTransition graph using free monads and existentials
Transition graph using free monads and existentials
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Metaprogramming in Haskell
Metaprogramming in HaskellMetaprogramming in Haskell
Metaprogramming in Haskell
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理
 
Haskell Jumpstart
Haskell JumpstartHaskell Jumpstart
Haskell Jumpstart
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
Kotlin Coroutines - the new async
Kotlin Coroutines - the new asyncKotlin Coroutines - the new async
Kotlin Coroutines - the new async
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
 
Perl세미나
Perl세미나Perl세미나
Perl세미나
 
6. processes and threads
6. processes and threads6. processes and threads
6. processes and threads
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
Programming simple games with a raspberry pi and
Programming simple games with a raspberry pi andProgramming simple games with a raspberry pi and
Programming simple games with a raspberry pi and
 

Recently uploaded

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

ああLazy io

  • 1. Non-Imperative Functional Programming 序章: 要求駆動I/O 2012-04-22 山下伸夫 nobsun@sampou.org
  • 2. IO は命令書だ main :: IO () main = do input <- openFile "i" ReadMode contents <- hGetContents input hClose input output <- openFile "o" WriteMode hPutStr output contents hClose output return ()
  • 3. すぐやらなくてもいいLazyな命令 書いちゃだめでしょ! main :: IO () main = do input <- openFile "i" ReadMode contents <- hGetContents input hClose input output <- openFile "o" WriteMode hPutStr output contents hClose output return ()
  • 4. 命令書と実行結果 main :: IO () main = do line1 <- getLine line2 <- getLine putStrLn line2 putStrLn line1 ghci> :main world!↓ Hello,↓ Hello, world!
  • 5. Lazyな命令があると? main :: IO () main = do line1 <- lazy getLine line2 <- lazy getLine putStrLn line2 putStrLn line1 return () ghci> :main ?
  • 6. Eagerな文脈にLazyな要素 main :: IO () main = do line1 <- lazy getLine line2 <- lazy getLine putStrLn line2 putStrLn line1 return () ghci> :main world!↓ world! Hello,↓ Hello,
  • 7. Eagerな文脈にLazyな要素 ! main :: IO () main = do line1 <- lazy getLine 険 line2 <- lazy getLine putStrLn line2 危 な putStrLn line1 る return () ghci> :main world!↓ ぜ world! Hello,↓ Hello, ま
  • 8. 全部Lazyにしてしまえ! main :: IO () main = do line1 <- lazy getLine line2 <- lazy getLine lazy (putStrLn line2) lazy (putStrLn line1) return () ghci> :main ?
  • 9. Lazy = 要求駆動 main :: IO () main = do line1 <- lazy getLine line2 <- lazy getLine lazy (putStrLn line2) ね lazy (putStrLn line1) return () だ ghci> :main 然 ghci> 当 。 ま
  • 10. 要求駆動I/O main :: IO () main = do line1 <- lazy getLine line2 <- lazy getLine prn2 <- lazy (putStrLn line2) prn1 <- lazy (putStrLn line1) return $! sequencing [force line1 ,force line2 ,prn2 ,prn1]
  • 11. 要求駆動I/O ス ー ! ォ え force :: a -> () force !x = () フ 使 を sequencing :: [()] -> () sequencing sq = case dropWhile (()==) sq of [] -> ()
  • 12. IO は命令書だ main :: IO () main = do input <- lazy $ openFile "i" ReadMode icloseR <- lazy $ hClose input output <- lazy $ openFile "o" WriteMode ocloseR <- lazy $ hClose output contents <- hGetContents input printR <- lazy $ hPutStr output contents return $! sequencing $ [printR,icloseR,ocloseR]
  • 13. ああ IO () main :: IO () main = do input <- lazy $ openFile "i" ReadMode icloseR <- lazy $ hClose input output <- lazy $ openFile "o" WriteMode ocloseR <- lazy $ hClose output contents <- hGetContents input printR <- lazy $ hPutStr output contents return $! sequencing $ [printR,icloseR,ocloseR]
  • 15. 対話:: a :-> b としてのI/O type a :-> b = OI a -> b mainR :: a :-> () runI :: (a :-> b) -> IO b main = runI mainR