SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
(* hogeは int lazy_t 型 *)
let hoge = lazy 1
$ cat test_ocaml.ml
let hoge = lazy 1 + 2
$ omake
*** omake: reading OMakefiles
*** omake: finished reading OMakefiles (0.01 sec)
- build . test_ocaml.cmi
+ ocamlfind ocamlopt -package oUnit -warn-error A -annot 
 -I . -c test_ocaml.ml
File "test_ocaml.ml", line 1, characters 11-17:
Error: This expression has type int lazy_t
       but an expression was expected of type int




let hoge = (lazy 1) + 2
(* hogeは int lazy_t 型 *)
let hoge = lazy (1 + 2)




let rec map f s = lazy (match s with
  | (lazy SSnil) -> SSnil
  | (lazy (SScons(x, s))) -> SScons(f x, map f s))
$ cat test_ocaml.ml
let hoge = lazy (1 + 2)

let _ = print_int (Lazy.force hoge)
(* (Lazy.force hoge) は Int 型 *)
$ ./test_ocaml
3
$ cat test_ocaml.ml
let hoge = lazy (1 + 2)

let _ = match hoge with
  | lazy i -> print_int i
$ ./test_ocaml
3
let plus (lazy m) (lazy n) = lazy (m + n)




let _ = let i = Lazy.force (plus (lazy 1) (lazy 2)) in
         print_int i
fun lazy plus ($m, $n) = $m+n



fun plus (x, y) = $case (x, y) of ($m, $n) => force ($m+n)




(* plus : int lazy_t -> int lazy_t -> int lazy_t *)
let plus m n = lazy(match (m, n) with
  | (lazy m, lazy n) -> m + n)
datatype a StreamCell = NIL | CONS of a * a Stream
withtype a Stream = a StreamCell susp



type 'a cell = SSnil | SScons of 'a * 'a stream
and 'a stream = 'a cell Lazy.t
fun lazy ($NIL) ++ t = t
     | ($CONS (x, s)) ++ t = $CONS (x, s ++ t)



let rec (++) t1 t2 = lazy (match (t1, t2) with
  | (lazy SSnil, lazy t2) -> t2
  | (lazy (SScons(x, s)), t2) -> SScons(x, s ++ t2))
fun lazy take (0, s) = $NIL
     | take (n, $NIL) = $NIL
     | take (n, $CONS (x, s)) = $CONS (x, take (n - 1, s))



let rec take n s = lazy (match (n, s) with
  | (0, _) -> SSnil
  | (_, lazy SSnil) -> SSnil
  | (n, lazy (SScons(x, s))) -> SScons(x, take (n - 1) s))
fun lazy drop (n, s) =
 let fun drop' (0, s) = s
      | drop' (n, $NIL) = $NIL
      | drop' (n, $CONS (x, s)) = drop' (n - 1, s)
 in drop' (n, s) end



let drop n s = lazy (
  let rec drop' n s = match (n, s) with
    | (0, lazy s) -> s
    | (_, lazy SSnil) -> SSnil
    | (n, lazy (SScons(_, s))) -> drop' (n - 1) s
  in drop' n s)
fun lazy reverse s =
 let fun reverse' ($NIL, r) = r
      | reverse' ($CONS (x, s), r) = reverse' (s, $CONS (x, r))
 in reverse' (s, $NIL) end



let reverse s = lazy (
  let rec reverse' s r = match (s, r) with
    | (lazy SSnil, r) -> r
    | (lazy (SScons(x, s)), r) -> reverse' s (lazy (SScons(x, r)))
  in Lazy.force (reverse' s (lazy SSnil)))
https://github.com/master-q/
readPurelyFunctionalDataStructures/
tree/master/LazyEvaluation

Mais conteúdo relacionado

Mais procurados

言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断nishio
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentationMartin McBride
 
正規表現のいろは
正規表現のいろは正規表現のいろは
正規表現のいろはAyumu Hanba
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)GroovyPuzzlers
 
Python built in functions
Python built in functionsPython built in functions
Python built in functionsRakshitha S
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in HaskellMasahiro Sakai
 

Mais procurados (12)

言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
Control de acceso con excel
Control de acceso con excelControl de acceso con excel
Control de acceso con excel
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
PHP 101
PHP 101 PHP 101
PHP 101
 
正規表現のいろは
正規表現のいろは正規表現のいろは
正規表現のいろは
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
 
Polynomials
PolynomialsPolynomials
Polynomials
 
Tabla derivadas
Tabla derivadasTabla derivadas
Tabla derivadas
 
SAT/SMT solving in Haskell
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
 

Destaque

Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: IntroductionKiwamu Okabe
 
Functional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformKiwamu Okabe
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OSKiwamu Okabe
 
Macrodown -MLが使えるML-
Macrodown -MLが使えるML-Macrodown -MLが使えるML-
Macrodown -MLが使えるML-T. Suwa
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS languageKiwamu Okabe
 
線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる啓 小笠原
 
Real-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageKiwamu Okabe
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?Kiwamu Okabe
 
Emacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, againEmacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, againKiwamu Okabe
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 

Destaque (10)

Functional IoT: Introduction
Functional IoT: IntroductionFunctional IoT: Introduction
Functional IoT: Introduction
 
Functional IoT: Hardware and Platform
Functional IoT: Hardware and PlatformFunctional IoT: Hardware and Platform
Functional IoT: Hardware and Platform
 
Functional IoT: Programming Language and OS
Functional IoT: Programming Language and OSFunctional IoT: Programming Language and OS
Functional IoT: Programming Language and OS
 
Macrodown -MLが使えるML-
Macrodown -MLが使えるML-Macrodown -MLが使えるML-
Macrodown -MLが使えるML-
 
Embedded application designed by ATS language
Embedded application designed by ATS languageEmbedded application designed by ATS language
Embedded application designed by ATS language
 
線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる線形型のある言語でLEDを光らせる
線形型のある言語でLEDを光らせる
 
Real-time OS system state captured by ATS language
Real-time OS system state captured by ATS languageReal-time OS system state captured by ATS language
Real-time OS system state captured by ATS language
 
Does Infer dream of design by contract?
Does Infer dream of design by contract?Does Infer dream of design by contract?
Does Infer dream of design by contract?
 
Emacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, againEmacs verilog-mode is coming to Debian, again
Emacs verilog-mode is coming to Debian, again
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 

Semelhante a PFDS 4章をOCamlに翻訳

Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPFilippo Vitale
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
BOXPLOT EXAMPLES in R And  An Example for BEESWARM:BOXPLOT EXAMPLES in R And  An Example for BEESWARM:
BOXPLOT EXAMPLES in R And An Example for BEESWARM:Dr. Volkan OBAN
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発TipsTakashi Kitano
 
Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1Luis Carlos Balcazar
 
PFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy RepresentationsPFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy Representations昌平 村山
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisSpbDotNet Community
 
Agda であそぼ
Agda であそぼAgda であそぼ
Agda であそぼerutuf13
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and GoEleanor McHugh
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesEelco Visser
 

Semelhante a PFDS 4章をOCamlに翻訳 (20)

Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Pdfcode
PdfcodePdfcode
Pdfcode
 
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSPSend + More = Money – Let’s mash 2 monads to solve a simple CSP
Send + More = Money – Let’s mash 2 monads to solve a simple CSP
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
BOXPLOT EXAMPLES in R And  An Example for BEESWARM:BOXPLOT EXAMPLES in R And  An Example for BEESWARM:
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
 
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
 
Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1Crea un archivo pdf en escala de grises que permite búsquedas 1
Crea un archivo pdf en escala de grises que permite búsquedas 1
 
PFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy RepresentationsPFDS 9.2.3 Lazy Representations
PFDS 9.2.3 Lazy Representations
 
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
 
FYP Final Presentation
FYP Final PresentationFYP Final Presentation
FYP Final Presentation
 
matlab codes.pdf
matlab codes.pdfmatlab codes.pdf
matlab codes.pdf
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
OTLN2012
OTLN2012OTLN2012
OTLN2012
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Oh Composable World!
Oh Composable World!Oh Composable World!
Oh Composable World!
 
Agda であそぼ
Agda であそぼAgda であそぼ
Agda であそぼ
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
Ch5b.ppt
Ch5b.pptCh5b.ppt
Ch5b.ppt
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Scope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languagesScope Graphs: A fresh look at name binding in programming languages
Scope Graphs: A fresh look at name binding in programming languages
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

PFDS 4章をOCamlに翻訳

  • 1.
  • 2.
  • 3. (* hogeは int lazy_t 型 *) let hoge = lazy 1
  • 4. $ cat test_ocaml.ml let hoge = lazy 1 + 2 $ omake *** omake: reading OMakefiles *** omake: finished reading OMakefiles (0.01 sec) - build . test_ocaml.cmi + ocamlfind ocamlopt -package oUnit -warn-error A -annot -I . -c test_ocaml.ml File "test_ocaml.ml", line 1, characters 11-17: Error: This expression has type int lazy_t but an expression was expected of type int let hoge = (lazy 1) + 2
  • 5. (* hogeは int lazy_t 型 *) let hoge = lazy (1 + 2) let rec map f s = lazy (match s with | (lazy SSnil) -> SSnil | (lazy (SScons(x, s))) -> SScons(f x, map f s))
  • 6. $ cat test_ocaml.ml let hoge = lazy (1 + 2) let _ = print_int (Lazy.force hoge) (* (Lazy.force hoge) は Int 型 *) $ ./test_ocaml 3
  • 7. $ cat test_ocaml.ml let hoge = lazy (1 + 2) let _ = match hoge with | lazy i -> print_int i $ ./test_ocaml 3
  • 8. let plus (lazy m) (lazy n) = lazy (m + n) let _ = let i = Lazy.force (plus (lazy 1) (lazy 2)) in print_int i
  • 9. fun lazy plus ($m, $n) = $m+n fun plus (x, y) = $case (x, y) of ($m, $n) => force ($m+n) (* plus : int lazy_t -> int lazy_t -> int lazy_t *) let plus m n = lazy(match (m, n) with | (lazy m, lazy n) -> m + n)
  • 10.
  • 11. datatype a StreamCell = NIL | CONS of a * a Stream withtype a Stream = a StreamCell susp type 'a cell = SSnil | SScons of 'a * 'a stream and 'a stream = 'a cell Lazy.t
  • 12. fun lazy ($NIL) ++ t = t | ($CONS (x, s)) ++ t = $CONS (x, s ++ t) let rec (++) t1 t2 = lazy (match (t1, t2) with | (lazy SSnil, lazy t2) -> t2 | (lazy (SScons(x, s)), t2) -> SScons(x, s ++ t2))
  • 13. fun lazy take (0, s) = $NIL | take (n, $NIL) = $NIL | take (n, $CONS (x, s)) = $CONS (x, take (n - 1, s)) let rec take n s = lazy (match (n, s) with | (0, _) -> SSnil | (_, lazy SSnil) -> SSnil | (n, lazy (SScons(x, s))) -> SScons(x, take (n - 1) s))
  • 14. fun lazy drop (n, s) = let fun drop' (0, s) = s | drop' (n, $NIL) = $NIL | drop' (n, $CONS (x, s)) = drop' (n - 1, s) in drop' (n, s) end let drop n s = lazy ( let rec drop' n s = match (n, s) with | (0, lazy s) -> s | (_, lazy SSnil) -> SSnil | (n, lazy (SScons(_, s))) -> drop' (n - 1) s in drop' n s)
  • 15. fun lazy reverse s = let fun reverse' ($NIL, r) = r | reverse' ($CONS (x, s), r) = reverse' (s, $CONS (x, r)) in reverse' (s, $NIL) end let reverse s = lazy ( let rec reverse' s r = match (s, r) with | (lazy SSnil, r) -> r | (lazy (SScons(x, s)), r) -> reverse' s (lazy (SScons(x, r))) in Lazy.force (reverse' s (lazy SSnil)))